在许多PyGTk教程中,事件处理程序的定义如下所示。
window.connect("destroy", self.close)
button.connect("clicked", self.print_hello_world)有没有任何类封装“销毁”,“点击”字符串文字,因为我想访问它们作为常量。
发布于 2013-05-17 01:44:10
在小型应用程序中,我们可能会编写如下代码:
class MyApp():
def __init__(self):
self.win = Gtk.Window()
self.win.set_size_request(400, 300)
self.win.connect('destroy', self.on_app_exit)
btn = Gtk.Button("hello")
btn.connect('clicked', self.on_button_clicked)
def run(self):
self.win.show_all()
Gtk.main()
def on_app_exit(self, window):
// do something.
Gtk.main_quit()
def on_button_clicked(self, btn):
print('hello, world')
def main():
app = MyApp()
app.run()
if __name__ == '__main__':
main()https://stackoverflow.com/questions/16316168
复制相似问题