runtimeerror缺少处理程序python glade

时间:2013-05-19 18:59:08

标签: python glade

这是我的一段代码

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)

glade文件显示相应的行:

<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()方法。

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

1 个答案:

答案 0 :(得分: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)'

感谢所有