正确关闭GTK对话窗口

时间:2014-03-31 22:06:01

标签: python-3.x gtk3 glade

我使用Glade,Python3,Gtk3构建应用程序。当我打开一个对话框窗口并再次关闭它时,我收到错误:

  TypeError: on_aboutdialog_destroy() takes 1 positional argument but 2 were given

我的应用程序如下所示:

  #!/usr/bin/env python

  from gi.repository import Gtk
  from gi.repository import Gio
  import sys

  class Handler:
        #Main Window
        def on_mainwindow_destroy(self):
              print("destroy window")
              Gtk.main_quit()

        #Menu items
        def on_menuquit_activate(self, menuitem):
              print("quit from menu")
              Gtk.main_quit()

        def on_menuabout_activate(self, menuitem, data=None):
              print("menu about activated")
              aboutdialog = builder.get_object("aboutdialog")
              aboutdialog.run()

        def on_aboutdialog_destroy(self):
              print("destroy about")
              aboutdialog.hide()


  builder = Gtk.Builder()
  builder.add_from_file("psn.glade")
  builder.connect_signals(Handler())

  window = builder.get_object("mainwindow")
  window.show_all()

  Gtk.main()

1 个答案:

答案 0 :(得分:1)

我在官方GTK论坛上得到了一些帮助。结束这样做:

    self.ab = self.builder.get_object("aboutdialog")

    def on_aboutdialog_destroy(self, widget):
        self.ab.hide()