与任何其他对话窗口一样,它们需要您
第一个将阻止主循环并在对话框收到响应后立即返回,这可能是,单击操作区域中的任何按钮或按Esc,或调用对话框的响应方法或"销毁"窗口,最后一个并不意味着窗口将被销毁,这意味着run()方法将退出并返回响应.像这样:
response = dialog.run()
Run Code Online (Sandbox Code Playgroud)
如果使用调试器,您会注意到主循环保持不变,直到您单击按钮或尝试关闭对话框.收到您的回复后,您可以根据需要使用.
response = dialog.run()
if response == gtk.RESPONSE_OK:
#do something here if the user hit the OK button
dialog.destroy()
Run Code Online (Sandbox Code Playgroud)
第二个允许您在非阻塞的东西中使用对话框,然后您必须将对话框连接到"响应"信号.
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)
Run Code Online (Sandbox Code Playgroud)
现在,您注意到必须销毁对话框
当您收到删除或取消信号时,您需要调用窗口小部件的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()
Run Code Online (Sandbox Code Playgroud)
您可以在GTK文档中找到响应类型常量
| 归档时间: |
|
| 查看次数: |
4773 次 |
| 最近记录: |