【发布时间】:2017-05-13 22:51:23
【问题描述】:
我正在 Python3 下学习 GTK3,并制作了一个到目前为止只有一个 AppWindow 的应用程序。 我正在使用 Gtk.Application。
我不知道如何正确处理打开第二个窗口。 我可以直接从我的主窗口打开它,但我不知道如何将 Application 对象传递给它(我用谷歌搜索并“duckduckgoed”没有任何成功)。
- 是否需要调用 Gtk.Application 才能打开第二个窗口?
- 如何让 Gtk.Application 跟踪这个新窗口?
应用是这样的:
- 带有来自数据库的对象列表的主窗口。
- 用于编辑从主窗口中选择的单个项目的第二个窗口 列表。
谢谢。
我的代码(我去掉了不必要的代码):
# ################################################################
# MAIN APP WINDOW
class AppWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Here all the widgets and a button to open the second window
self.show_all()
# ################################################################
# MAIN APP CLASS
class Application(Gtk.Application):
def __init__(self, *args, **kwargs):
super().__init__(*args, application_id=MIKUNA_ID,
**kwargs)
self.window = None
def do_startup(self):
Gtk.Application.do_startup(self)
action = Gio.SimpleAction.new("quit", None)
action.connect("activate", self.on_quit)
self.add_action(action)
def do_activate(self):
# We only allow a single window and raise any existing ones
if not self.window:
# Windows are associated with the application
# when the last one is closed the application shuts down
self.window = AppWindow(application=self, title="Mikuna")
self.window.present()
def on_quit(self, action, param):
self.quit()
if __name__ == "__main__":
app = Application()
app.run(sys.argv)
【问题讨论】:
标签: python python-3.x user-interface gtk3 pygobject