ondestroy 不执行回调函数

发布于 2024-12-03 18:39:11 字数 1423 浏览 3 评论 0原文

我正在使用 python gtk+ 和glade 开发一个应用程序。我的空地文件格式是 gtk-builder。我有两个窗口 - 一个主窗口和一个登录窗口。在 __ init __ () 中,我运行登录对话框窗口,这样我就可以确保焦点不会切换到主窗口,直到用户发出 OK 信号登录窗口。使用以下代码完成此操作后,用户必须单击标题栏上的 [x] 两次才能退出应用程序。当我使用 loginWindow.show() 而不是 run() 时,它工作得很好,但焦点问题出现在那里。我该如何解决这个问题?

import sys
try:
    import pygtk
    pygtk.require("2.8")
except:
    pass
try:
    import gtk
except:
    sys.exit(1)


class netChat:
    def __init__(self):
        self.builder = gtk.Builder()
        self.builder.add_from_file("netchat.glade")
        self.builder.connect_signals(self)
        self.loginWindow = self.builder.get_object('loginWindow')
        self.mainWindow = self.builder.get_object('mainWindow')
        self.message = self.builder.get_object('message')
        self.timeLine = self.builder.get_object('timeLine')
        self.loginWindow.run()
    def onSend(self, widget):
        text = self.message.get_text()
        myBuffer = self.timeLine.get_buffer()
        myBuffer.insert_at_cursor(' '+text+'\n')
        self.message.set_text('')
        print "on Send"
    def mainQuit(self, widget):
        print "Quiting, goodbye!"
        sys.exit(0)
    def loginQuit(self, widget):
        print "Login Quit, goodbye!"
        sys.exit(1)

if __name__ == "__main__":
    myChat = netChat()
    gtk.main()

我也尝试为两个窗口设置相同的 mainQuit() 回调。但这没有任何区别。感谢您的任何帮助。

I'm developing an application using python gtk+ and glade. My glade file format is gtk-builder. I've two windows in it - one main window and one login window. Inside __ init __ () I run the login dialog window, so that I can make sure the focus will not be switched to the main window until the user emits OK signal from the login window. When this is done using the following code, the user has to click twice on the [x] on the titlebar, to quit the application. When I use loginWindow.show() rather than the run(), it works perfect, but the focus issue arises there. How can I fix this issue?

import sys
try:
    import pygtk
    pygtk.require("2.8")
except:
    pass
try:
    import gtk
except:
    sys.exit(1)


class netChat:
    def __init__(self):
        self.builder = gtk.Builder()
        self.builder.add_from_file("netchat.glade")
        self.builder.connect_signals(self)
        self.loginWindow = self.builder.get_object('loginWindow')
        self.mainWindow = self.builder.get_object('mainWindow')
        self.message = self.builder.get_object('message')
        self.timeLine = self.builder.get_object('timeLine')
        self.loginWindow.run()
    def onSend(self, widget):
        text = self.message.get_text()
        myBuffer = self.timeLine.get_buffer()
        myBuffer.insert_at_cursor(' '+text+'\n')
        self.message.set_text('')
        print "on Send"
    def mainQuit(self, widget):
        print "Quiting, goodbye!"
        sys.exit(0)
    def loginQuit(self, widget):
        print "Login Quit, goodbye!"
        sys.exit(1)

if __name__ == "__main__":
    myChat = netChat()
    gtk.main()

I tried setting the same mainQuit() callback for both of the windows too. But that didn't make any difference. Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天邊彩虹 2024-12-10 18:39:11

您似乎遇到了重入问题。您可能正在通过登录对话框中“确定”按钮的 onClick 运行主窗口。

也许您多次调用 gtk.main()

很难猜测,因为您的代码不完整。

It looks like you have a reentry issue. Probably you are running the main window from the onClick of the "ok" button in the login dialog.

Maybe you are calling gtk.main() several times?

It is difficult to guess, since your code is not complete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文