首页 文章

glade aboutDialog并未关闭

提问于
浏览
3

我有一个用glade制作的 AboutDialog 框,但是Close按钮不知道如何将这个按钮连接到一个单独的函数,因为它位于一个名为 dialog-action_area 的小部件中 .

另一个问题是如果我使用窗口管理器创建的关闭按钮,我无法再次打开它,因为它已被销毁 .

我怎么能改变这个只是隐藏?

2 回答

  • 6

    与任何其他对话窗口一样,它们需要您

    • 使用run方法 .

    • 使用"reponse"信号

    第一个将阻止主循环并在对话框收到响应后立即返回,这可能是,单击操作区域中的任何按钮或按Esc,或调用对话框的响应方法或“销毁”窗口,最后一个并不意味着窗口将被销毁,这意味着run()方法将退出并返回响应 . 像这样:

    response = dialog.run()
    

    如果使用调试器,您会注意到主循环保持不变,直到您单击按钮或尝试关闭对话框 . 收到您的回复后,您就可以根据需要使用 .

    response = dialog.run()
    if response == gtk.RESPONSE_OK:
        #do something here if the user hit the OK button 
    dialog.destroy()
    

    第二个允许您在非阻塞的东西中使用对话框,然后您必须将对话框连接到“响应”信号 .

    def do_response(dialog, response):
        if response == gtk.RESPONSE_OK:
            #do something here if the user hit the OK button 
        dialog.destroy()
    
    dialog.connect('response', do_response)
    

    现在,您注意到必须销毁对话框

  • 5

    当您收到删除或取消信号时,您需要调用窗口小部件的hide()方法:

    response = self.wTree.get_widget("aboutdialog1").run() # or however you run it
    if response == gtk.RESPONSE_DELETE_EVENT or response == gtk.RESPONSE_CANCEL:
      self.wTree.get_widget("aboutdialog1").hide()
    

    你可以找到响应类型常量in the GTK documentation

相关问题