【发布时间】:2020-12-18 16:19:54
【问题描述】:
我正在用 python 和 GTK (PyGobject) 编写一个 GUI 应用程序。这是我的应用程序类:
class Application(Gtk.Application):
def __init__(self, *args, **kwargs):
super().__init__(*args, application_id='org.tractor.carburetor', **kwargs)
self.window = None
self.prefs = None
self.about = None
def do_startup(self):
Gtk.Application.do_startup(self)
action = Gio.SimpleAction.new('preferences', None)
action.connect('activate', self.on_preferences)
self.add_action(action)
action = Gio.SimpleAction.new('about', None)
action.connect('activate', self.on_about)
self.add_action(action)
action = Gio.SimpleAction.new("quit", None)
action.connect('activate', self.on_quit)
self.add_action(action)
def do_activate(self):
if not self.window:
window = AppWindow(application=self) #GtkApplicationWindow
self.window = window
self.window.present()
def on_preferences(self, action, param):
if not self.prefs:
prefs_window = ui.get('PreferencesWindow') #HdyPreferencesWindow
prefs_window.set_transient_for(self.window)
self.prefs = prefs_window
self.prefs.show()
def on_about(self, action, param):
if not self.about:
about_dialog = ui.get('AboutDialog') #GtkAboutDialog
about_dialog.set_transient_for(self.window)
self.about = about_dialog
self.about.show()
def on_quit(self, action, param):
self.quit()
当我在应用程序菜单中单击首选项或关于时,一切都很好。但是关闭对话框后,如果我再次单击它们,则会出现错误并出现一个空窗口。
以下是错误:
(carburetor:157852): Gtk-CRITICAL **: 19:41:29.887: gtk_widget_show: assertion
'GTK_IS_WIDGET (widget)' failed
(carburetor:157852): Gtk-CRITICAL **: 19:41:29.887: gtk_label_set_markup:
assertion 'GTK_IS_LABEL (label)' failed
【问题讨论】:
标签: python user-interface gtk gtk3 pygobject