0

这是我的一段代码

class gui_manage():
    def delete_event(self , widget , data):
        False
        print 'delete'
    # #######################
    # define some functions here
     as example : start_download(self ,widget)
    ########################################
    def start_download( self , widget  ):
        print 'add_url_clicked'

    def __init__(self):
        builder = gtk.Builder()
        builder.add_from_file('gui.glade')
        win=builder.get_object('add_url_win')
        text_entry= builder.get_object('url_entry')
        signals ={ 
         'delete_event' : self.delete_event , 
         'destroy' : self.destroy  ,
         'cancel_button_clicked' : self.delete_event , 
         'addpaused_button_clicked' : self.addpaused ,
     'start_download_clicked' : self.start_download , 
         'addpaused_button_clicked' : self.addpaused 
         }
        builder.connect_signals(signals)

林间空地文件显示了相应的行:

<object class="GtkButton" id="start_download">
    <property name="label" translatable="yes">start download</property>
      <property name="visible">True</property>
           <property name="can_focus">True</property>
           <property name="receives_default">True</property>
      <property name="tooltip_text" translatable="yes">start download now ...</property>
    <property name="use_action_appearance">False</property>
<signal name="clicked" handler="start_download" swapped="no"/>'

我得到了错误:

gui_manage.py:45: RuntimeWarning: missing handler 'start_download'
  builder.connect_signals(signals)

但是,delete_event()通过单击“取消按钮的事件”调用的方法成功。

简而言之,所有方法都以相同的方式定义,连接在同一个字典中,尽管缺少一些!

4

1 回答 1

0

现在效果很好:

'def start_download( self , object  ):
    print 'add_url_clicked''

代替

'def start_download( self , widget  ):
    print 'add_url_clicked''

&

'self.signals = {}'

代替

'signals = {}'

&

'self.builder.connect_signals(self)'

代替

'self.builder.connect_signals(signals)'

谢谢大家

于 2013-05-31T07:01:06.083 回答