我完成了一个应用程序设计,没有发生任何有用的事情,但我有两个窗口。一个是主窗口,一个是关于对话。它们都在 Glade 的一个 .ui 文件中。
当我使用帮助>关于(在我的程序中)打开关于对话框时,一切正常。使用相同的方法将其关闭并再次打开会导致空白窗口。
这是我的代码:
#! /usr/bin/env python3
from gi.repository import Gtk
class window():
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file("./personalinfo.ui")
self.mainWindow = self.builder.get_object("mainWindow")
self.mainWindow.connect("destroy", self.on_mainWindow_destroy)
self.mainWindow.set_title("Persona")
self.mainWindowMainBoxButtonBoxCancel = self.builder.get_object("mainWindowMainBoxButtonBoxCancel")
self.mainWindowMainBoxButtonBoxCancel.connect("clicked", self.on_mainWindowMainBoxButtonBoxCancel_clicked)
self.mainWindowMainBoxButtonBoxOK = self.builder.get_object("mainWindowMainBoxButtonBoxOK")
self.mainWindowMainBoxButtonBoxOK.connect("clicked", self.on_mainWindowMainBoxButtonBoxOK_clicked)
self.mainWindowMainBoxGenderBoxCombo = self.builder.get_object("mainWindowMainBoxGenderBoxCombo")
self.mainWindowMainBoxGenderBoxCombo.set_active(0)
self.mainWindowMainBoxMenuFileMenuQuit = self.builder.get_object("mainWindowMainBoxMenuFileMenuQuit")
self.mainWindowMainBoxMenuFileMenuQuit.connect("activate", self.on_mainWindowMainBoxMenuFileMenuQuit_activate)
self.mainWindowMainBoxMenuHelpMenuAbout = self.builder.get_object("mainWindowMainBoxMenuHelpMenuAbout")
self.mainWindowMainBoxMenuHelpMenuAbout.connect("activate", self.on_mainWindowMainBoxMenuHelpMenuAbout_activate)
self.mainWindow.show_all()
def on_mainWindow_destroy(self, widget):
print("destroy: 'mainWindow'")
Gtk.main_quit()
def on_mainWindowMainBoxButtonBoxCancel_clicked(self, widget):
print("clicked: 'mainWindowMainBoxButtonBoxCancel'")
Gtk.main_quit()
def on_mainWindowMainBoxButtonBoxOK_clicked(self, widget):
print("clicked: 'mainWindowMainBoxButtonBoxOK'")
Gtk.main_quit()
def on_mainWindowMainBoxMenuFileMenuQuit_activate(self, widget):
print("activate: 'mainWindowMainBoxMenuFileMenuQuit'")
Gtk.main_quit()
def on_mainWindowMainBoxMenuHelpMenuAbout_activate(self, widget):
print("activate: 'mainWindowMainBoxMenuHelpMenuAbout'")
self.aboutWindow = self.builder.get_object("aboutWindow")
self.aboutWindow.set_title("About Persona")
self.aboutWindowMainBoxButtonBoxOK = self.builder.get_object("aboutWindowMainBoxButtonBoxOK")
self.aboutWindowMainBoxButtonBoxOK.connect("clicked", self.on_aboutWindowMainBoxButtonBoxOK_clicked)
self.aboutWindow.show_all()
def on_aboutWindowMainBoxButtonBoxOK_clicked(self, widget):
print("clicked: 'aboutWindowMainBoxButtonBoxOK'")
self.aboutWindow.destroy()
w = window()
Gtk.main()