- Tkinter GUI Application Development Cookbook
- Alejandro Rodas de Paz
- 183字
- 2021-08-27 19:43:59
How it works...
First, we replaced the wildcard import with the import ... as syntax to have better control over our global namespace.
Then, we defined our App class as a Tk subclass, which now is referenced via the tk namespace. To properly initialize the base class, we will call the __init__ method of the Tk class with the built-in super() function. This corresponds to the following lines:
class App(tk.Tk): def __init__(self): super().__init__() # ...
Now, we have a reference to the App instance with the self variable, so we will add all the Button widget as an attribute of our class.
Although it may look overkill for such a simple program, this refactoring will help us to reason about each part, the button instantiation is separated from the callback that gets executed when it is clicked, and the application bootstrapping is moved to the if __name__ == "__main__" block, which is a common practice in executable Python scripts.
We will follow this convention through all the code samples, so you can take this template as the starting point of any larger application.
- MySQL數據庫應用與管理 第2版
- SAP BusinessObjects Dashboards 4.1 Cookbook
- 利用Python進行數據分析(原書第3版)
- 區塊鏈底層設計Java實戰
- Keras深度學習實戰
- Geospatial Development By Example with Python
- 案例式C語言程序設計實驗指導
- 區塊鏈架構之美:從比特幣、以太坊、超級賬本看區塊鏈架構設計
- Simulation for Data Science with R
- MongoDB Cookbook(Second Edition)
- AMP:Building Accelerated Mobile Pages
- Practical Responsive Typography
- Raspberry Pi開發實戰
- 新手學ASP.NET 3.5網絡開發
- ACE技術內幕:深入解析ACE架構設計與實現原理