- Tkinter GUI Application Development Blueprints(Second Edition)
- Bhaskar Chaudhary
- 297字
- 2021-06-24 18:35:03
Ways to create widgets
There are two ways to create widgets in Tkinter.
The first way involves creating a widget in one line and then adding the pack() method (or other geometry managers) in the next line, as follows:
my_label = tk.Label(root, text="I am a label widget")
my_label.pack()
Alternatively, you can write both the lines together, as follows:
tk.Label(root, text="I am a label widget").pack()
You can either save a reference to the widget created ( my_label, as in the first example), or create a widget without keeping any reference to it (as demonstrated in the second example).
You should ideally keep a reference to the widget in case the widget has to be accessed later on in the program. For instance, this is useful in case you need to call one of its internal methods or for its content modification. If the widget state is supposed to remain static after its creation, you need not keep a reference to the widget.
my_label = tk.Label(...)
my_label.pack()
This is one of the most common mistakes committed by beginners.
- Android Wearable Programming
- Google Apps Script for Beginners
- Python科學計算(第2版)
- 從程序員到架構師:大數據量、緩存、高并發、微服務、多團隊協同等核心場景實戰
- Building Cross-Platform Desktop Applications with Electron
- CKA/CKAD應試教程:從Docker到Kubernetes完全攻略
- 深入理解Elasticsearch(原書第3版)
- 前端HTML+CSS修煉之道(視頻同步+直播)
- C語言程序設計
- Test-Driven Development with Django
- C語言程序設計實踐
- 會當凌絕頂:Java開發修行實錄
- Mastering Apache Camel
- AutoCAD基礎教程
- Joomla!Search Engine Optimization