- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 74字
- 2021-08-27 19:43:58
How to do it...
To improve the modularity of our simple program, we will define a class that wraps our global variables:
import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.btn = tk.Button(self, text="Click me!", command=self.say_hello) self.btn.pack(padx=120, pady=30) def say_hello(self): print("Hello, Tkinter!") if __name__ == "__main__": app = App() app.title("My Tkinter app") app.mainloop()
Now, each variable is enclosed in a specific scope, including the command function, which is moved as a separate method.
推薦閱讀
- Learning Java Functional Programming
- Modular Programming with Python
- 計算機圖形學編程(使用OpenGL和C++)(第2版)
- FreeSWITCH 1.6 Cookbook
- Blockly創意趣味編程
- C語言從入門到精通(第4版)
- 軟件測試技術指南
- 數據結構案例教程(C/C++版)
- Learning Apache Karaf
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- D3.js By Example
- 持續集成與持續交付實戰:用Jenkins、Travis CI和CircleCI構建和發布大規模高質量軟件
- 精通MySQL 8(視頻教學版)
- Mastering Apache Storm
- Getting Started with Polymer