- Tkinter GUI Application Development Blueprints(Second Edition)
- Bhaskar Chaudhary
- 353字
- 2021-06-24 18:35:03
Adding widgets to a parent window
The format used to add widgets is the same as the one that we discussed in the previous task. To give you an idea about how it's done, here's some sample code that adds some common widgets:
Label(parent, text="Enter your Password:")
Button(parent, text="Search")
Checkbutton(parent, text="Remember Me", variable=v, value=True)
Entry(parent, width=30)
Radiobutton(parent, text="Male", variable=v, value=1)
Radiobutton(parent, text="Female", variable=v, value=2)
OptionMenu(parent, var, "Select Country", "USA", "UK", "India","Others")
Scrollbar(parent, orient=VERTICAL, command= text.yview)
Can you spot the pattern that is common to each widget? Can you spot the differences?
As a reminder, the syntax for adding a widget is as follows:
Widget-name(its_parent, **its_configuration_options)
Using the same pattern, let's add all the 21 core Tkinter widgets into a dummy application (1.03.py). We do not reproduce the entire code here. A summarized code description for 1.03.py is as follows:
- We create a top-level window and a mainloop, as shown in the earlier examples.
- We add a frame widget and name it menu_bar. Note that frame widgets are just holder widgets that hold other widgets. Frame widgets are great for grouping widgets together. The syntax for adding a frame is the same as that for all the other widgets:
frame = Frame(root)
frame.pack()
- Keeping the menu_bar frame as the container, we add two widgets to it:
- Menubutton
- Menu
- We create another frame widget and name it frame. Keeping frame as the container/parent widget, we add the following seven widgets to it:
- Label
- Entry
- Button
- Checkbutton
- Radiobutton
- OptionMenu
- Bitmap Class
- We then proceed to create another frame widget. We add six more widgets to the frame:
- Image Class
- Listbox
- Spinbox
- Scale
- LabelFrame
- Message
- We then create another frame widget. We add two more widgets to the frame:
- Text
- Scrollbar
- We create another frame widget and add two more widgets to it:
- Canvas
- PanedWindow
These constitute the 21 core widgets of Tkinter. Now that you have had a glimpse of all the widgets, let's discuss how to specify the location of these widgets using geometry managers.
推薦閱讀
- Web應(yīng)用系統(tǒng)開發(fā)實(shí)踐(C#)
- Software Testing using Visual Studio 2012
- Instant Zepto.js
- 神經(jīng)網(wǎng)絡(luò)編程實(shí)戰(zhàn):Java語言實(shí)現(xiàn)(原書第2版)
- Selenium Design Patterns and Best Practices
- Internet of Things with Intel Galileo
- 征服RIA
- 零基礎(chǔ)學(xué)Python數(shù)據(jù)分析(升級版)
- 前端HTML+CSS修煉之道(視頻同步+直播)
- 移動互聯(lián)網(wǎng)軟件開發(fā)實(shí)驗(yàn)指導(dǎo)
- 編程可以很簡單
- Node.js 12實(shí)戰(zhàn)
- Unity Character Animation with Mecanim
- Oracle數(shù)據(jù)庫編程經(jīng)典300例
- SQL Server 入門很輕松(微課超值版)