GtkAboutDialog 关闭按钮错误
我使用 GtkAboutDialog,除了这个小部件的关闭按钮之外,一切正常。所有其他按钮都工作正常,我不知道如何,但所有按钮都有默认回调,并且它们创建和销毁窗口。 但是 GtkAboutDialog 小部件的“关闭”按钮不起作用。我什至看不到它的小部件。那么,我可以访问它吗?
[澄清] 您看到的是 gtk.AboutDialog — 显示有关应用程序信息的弹出窗口(PyGTK 2.6 中的新增功能)。该窗口包含“关闭”按钮小部件,该小部件包含在 GtkHButtonBox 小部件中。 GtkHButtonBox 小部件是我能够访问的最高级别的小部件。关于如何到达“关闭”按钮并连接回调信号的处理程序有什么想法吗?
I use GtkAboutDialog and everything works fine except the close button of this widget. All other buttons works fine, I don't know how but all buttons have default callbacks and they create and destroy the windows.
But the "Close" button of GtkAboutDialog widget does not work. I can not even see it's widget. So, can I access it?
[CLARIFICATION] What you're looking at is gtk.AboutDialog — popup window displaying information about an application (new in PyGTK 2.6). This window contains the 'close' button widget which is contained in a GtkHButtonBox widget. The GtkHButtonBox widget is the highest level widget I am able to access for some. Any ideas on how to get to the "close" button and connect a handler for a callback signal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对话框的信号连接方式与窗口的连接方式不同。我在学习PyGTK时也犯过同样的错误。
对话框最基本的形式是显示并运行对话框:
通常您会立即调用:
.run() 行是一个循环,它一直运行直到对话框中发生某些情况。
这里有一个有效的示例。
You don't conenct signals in the same way for a dialog as you do for a window. I made the same mistake when learning PyGTK.
The most basic form of a dialog is you display and run the dialog with:
Often you will then immediately call:
The .run() line is a loop, which runs until something happens within the dialog.
There is a working example here.
gtk.AboutDialog
只是一个gtk.Dialog
,您可以以相同的方式处理来自它的响应。对话框代码不会连接到按钮的单击信号,而是为您处理该信号并从run()
调用返回响应。您可以检查返回的响应值来确定单击了哪个按钮。如果您尝试覆盖某些行为,则可以连接到
gtk.Dialog
的response
信号。The
gtk.AboutDialog
is just agtk.Dialog
, and you handle responses from it in the same way. Instead of connecting to the clicked signal of the buttons, the dialog code handles that for you and returns a reponse from yourrun()
call. You can check the value of the response returned to figure out what button was clicked.If you're trying to override some behaviour instead, you can connect to the
response
signal ofgtk.Dialog
.这是一个老问题,但由于它是谷歌的第一批点击之一,我想我应该提出我找到的解决方案。您需要一个事件处理程序来显示“关于”对话框,并需要一个事件处理程序来关闭它。第一个可能会连接到您的 help->about menuitem 的
activate
信号。后者应该连接到 about 对话框的response
信号。这两个处理程序将如下所示:在上面的示例中,我使用
GtkBuilder
来查找我的 about 对话框,因为我已经使用 Glade 构建了界面。请注意,我使用.show()
而不是.run()
,因为我看不到在对话框关闭之前暂停程序执行的意义。最后,可以使响应处理程序根据响应采取任何操作,但我在这里忽略它。This is an old question, but since it's one of the first hits from google, I thought I'd throw in the solution that I found. You need an event handler to show the about dialog and one to close it. The first will likely be connected to your help->about menuitem's
activate
signal. The latter should be connected to theresponse
signal of the about dialog. The two handlers will look something like this:In the example above, I'm using the
GtkBuilder
to find my about dialog because I've constructed the interface with glade. Note that I'm using.show()
over.run()
because I don't see the sense in pausing program execution until the dialog is closed. Finally, the response handler can be made to take whatever action depending upon the response, but I'm ignoring it here.