当Canonical-快速设置一个新项目时,它有"关于对话框的以下行":
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()
错误:
" Traceback(最近一次调用最后一次): 文件" psn_main.py",第21行,在on_menuabout_activate中 response = aboutdialog.run() NameError:name' aboutdialog'未定义"
答案 0 :(得分:0)
我使用以下代码使其工作。该功能由调用" on_menuabout_activate"的菜单项激活。它会向控制台输出调试消息。然后它从glade文件中获取aboutdialog-window并运行它:
def on_menuabout_activate(self, menuitem, data=None):
print("menu about activated")
aboutdialog = builder.get_object("aboutdialog")
aboutdialog.run()