0
在很多PyGTk教程中,事件處理程序的定義如下。PyGTK事件定義類
window.connect("destroy", self.close)
button.connect("clicked", self.print_hello_world)
是否有任何類封裝「銷燬」,「點擊」字符串文字,因爲我想訪問它們作爲常量。
在很多PyGTk教程中,事件處理程序的定義如下。PyGTK事件定義類
window.connect("destroy", self.close)
button.connect("clicked", self.print_hello_world)
是否有任何類封裝「銷燬」,「點擊」字符串文字,因爲我想訪問它們作爲常量。
在小型應用程序,我們可以這樣寫代碼:
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()