The best python GUI Programming (Tkinter) Tutorial In 2024, In this tutorial you can learn Tkinter Programming,Tkinter module,Standard property,Geometry Management,
python provides several graphical development interface library, several commonly used Python GUI library as follows:
Tkinter standard Python GUI library. Python using Tkinter can quickly create GUI applications.
Since Tkinter is built into python installation package, then as long as you can import Tkinter installed Python libraries, but IDLE is written using Tkinter made for a simple graphical interface Tkinter still be able to cope.
Creating a GUI program
Example:
#!/usr/bin/python # -*- coding: UTF-8 -*- import Tkinter top = Tkinter.Tk() # 进入消息循环 top.mainloop()
The results of the above code is executed as follows:
Example 2:
#!/usr/bin/python # -*- coding: UTF-8 -*- from Tkinter import * # 导入 Tkinter 库 root = Tk() # 创建窗口对象的背景色 # 创建两个列表 li = ['C','python','php','html','SQL','java'] movie = ['CSS','jQuery','Bootstrap'] listb = Listbox(root) # 创建两个列表组件 listb2 = Listbox(root) for item in li: # 第一个小部件插入数据 listb.insert(0,item) for item in movie: # 第二个小部件插入数据 listb2.insert(0,item) listb.pack() # 将小部件放置到主窗口中 listb2.pack() root.mainloop() # 进入消息循环
The results of the above code is executed as follows:
Tkinter provides a variety of controls, such as buttons, labels and text boxes, a GUI application use. These controls are usually referred to as controls or components.
There are 15 kinds of Tkinter parts. We make these components as well as a brief description, in the following table:
Controls | description |
---|---|
Button | Button control; display button in the program. |
Canvas | Canvas control; display graphical elements such as lines or text |
Checkbutton | Checkbox controls; for providing a multiple choice box in the program |
Entry | Input control; for displaying simple text content |
Frame | Frame control; display a rectangular area on the screen, usually used as a container |
Label | Tab control; can display text and bitmaps |
Listbox | List box control; in Listbox widget is used to display a list of strings to the user |
Menubutton | Menu button controls, because the menu item is displayed. |
Menu | Menu control; display the menu bar, drop-down menus and pop-up menus |
Message | Message control; to display multiple lines of text more similar, with label |
Radiobutton | Radio button controls; displays a radio button states |
Scale | Range control; display a numerical scale, limited range of digital output interval |
Scrollbar | Scrollbar control when the content exceeds the visualization area use, such as list boxes. . |
Text | Text controls; used to display multiple lines of text |
Toplevel | Container control; to provide a separate dialog box, and compare similar Frame |
Spinbox | Input controls; similar to the Entry, but you can specify the input range of values |
PanedWindow | PanedWindow is a window layout management plug-ins, you can contain one or more child controls. |
LabelFrame | labelframe is a simple container control. Common and complex window layouts. |
tkMessageBox | It displays a message box for your application. |
Standard attribute that is common property of all the controls, such as size, font and color, and so on.
Attributes | description |
Dimension | Control size; |
Color | Control color; |
Font | Control font; |
Anchor | Anchor; |
Relief | Control style; |
Bitmap | bitmap; |
Cursor | cursor; |
Tkinter control has specific geometric state management methods, management controls the entire regional organizations, what is Tkinter disclosed geometry manager class: pack, grid position
Geometric method | description |
pack () | package; |
grid () | grid; |
place () | position; |