当 Canonical-Quickly 建立一个新项目时,它的“关于对话框”有以下行:
self.AboutDialog = AboutNewAppDialog
我在 glade 中编辑了菜单项,并将以下代码添加到主窗口的 python 代码中:
self.menuabout = self.builder.get_object("menuabout")
和
def on_menuabout_activate(self, menuitem, data=None):
print("About activated")
self.response = self.AboutDialog.run()
self.AboutDialog.hide()
但这会产生错误:
self.response = self.AboutDialog.run()
TypeError: run() takes exactly 1 argument (0 given)
我也在学习使用类似语法的本教程:http: //gnipsel.com/glade/glade02b.html
当我将 Gtk.Dialog 放入括号时,程序崩溃:
self.response = self.AboutDialog.run(Gtk.Dialog)
我的第二次尝试:
#!/usr/bin/env python
from gi.repository import Gtk
class Handler:
def on_mainwindow_destroy(self, menuitem):
print("destroy window")
Gtk.main_quit()
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")
response = aboutdialog.run()
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()
错误:
“回溯(最后一次调用):文件“psn_main.py”,第 21 行,on_menuabout_activate 响应 = aboutdialog.run() NameError:未定义名称“aboutdialog””