- Tkinter GUI Programming by Example
- David Love
- 342字
- 2021-08-27 18:49:07
How will the code be structured?
Tkinter exposes many classes. These are known as widgets. A widget is typically any part of the application that needs to be drawn onto the screen, including the main window.
A Tkinter application always needs to have a main window. This is what will be drawn on the screen for the user to see. This is crucial for any GUI application, so much so that if you do not define one, Tkinter will try to create one for you (though you should never rely on this!). The widget that performs this job is called Tk.
The Tk widget exposes various window properties, such as the text within the top bar of the application, the size of the application, its position on screen, whether it can be resized, and even the icon which appears in the top right-hand corner (on Windows only).
Because of this feature exposure, it is very common for the main class of an application to inherit from the Tk widget, though any Tkinter widget can be subclassed to add program-specific functionality.
There is no set convention for what the subclass should be called. Some like to call it Root, some choose App, and others (such as myself) prefer to name it after the program itself. For example, a shopping list program would have a class called ShoppingList that inherits from Tk. Bear this in mind when looking through other sources of information on Tkinter.
Once you have a main window defined, you can begin adding other widgets into it. All other widgets must belong to a parent which has the ability to display them, such as a Tk or Frame. Each widget is only visible if its parent is. This allows us to group widgets into different screens and show or hide groups of them as need be.
Widgets are placed into their parents using special functions called geometry managers. There are three geometry managers available in Tkinter – pack, grid, and place. Let's take a look at each of them in detail.
- C++面向?qū)ο蟪绦蛟O(shè)計(jì)(第三版)
- Learning Data Mining with Python
- Python從入門到精通(精粹版)
- 秒懂設(shè)計(jì)模式
- 數(shù)據(jù)結(jié)構(gòu)案例教程(C/C++版)
- Scala Reactive Programming
- 軟件測(cè)試實(shí)用教程
- Learning Docker Networking
- 工業(yè)機(jī)器人離線編程
- Python Deep Learning
- 深度學(xué)習(xí)入門:基于Python的理論與實(shí)現(xiàn)
- AutoCAD基礎(chǔ)教程
- Using Yocto Project with BeagleBone Black
- 零基礎(chǔ)PHP從入門到精通
- Python深度學(xué)習(xí)與項(xiàng)目實(shí)戰(zhàn)