There are 15 controls for us to use in the Tkinter module. Let's give a brief introduction to these controls first.
Provide a button that triggers an event when clicked.
Provide a canvas, which is the size of the GUI interface.
Create the main application window.
Selectable multiple buttons.
Provides an input box to enter information from the keyboard.
Provides a window that can host other controls.
Provide a label that can display text or images.
Provides a list box from which one can be selected.
Provides a menu bar to select one.
Menu button.
Message text box.
Radio button, you can only select one of multiple buttons
Slider.
scrollbar.
Provides a text for the user to enter information.
Create a pop-up window.
To create a graphical interface, we must first have a window for us to add other controls. To add a window, use tkinter's Tk() function. The syntax format is:
window=tkinter.Tk()window.mainloop()
window is the name of the window we created, followed by the usage method. tkinter.mainloop() registers the call manager to respond to the event, that is, to start this window. Look at the code below:
importtkinterwindow=tkinter.Tk()window.mainloop()
Running results:
If you want to manage the maximum and minimum sizes of the window, use the following method:
importtkinterwindow=tkinter.Tk()window.minsize(366,366)#Minimum size window.maxsize(566,566)#Maximum size window.mainloop()
If we want to add text or pictures in the window, we can use the Label control as follows:
importtkinterdefmain():win=tkinter.Tk()win.minsize(366,366)#Minimum size win.maxsize(888,888)#Maximum size area_one=tkinte r.Label(win,text='Thisisarea_one',font=(Chinese regular script,20),fg=red)area_one.pack(side='left')area_two=tkinter.Label( win,text='Thisisarea_two',font=(黑体,20),fg=blue)area_two.pack(side='right')area_three=tkinter.Label(win,text='Thisisarea_three',font=(宋体,20 ),fg=black)area_three.pack()win.mainloop()if__name__=='__main__':main()
The running result is as shown in the figure:
Let's explain this example. The form of component addition is:
Component name=tkinter.Label (placed window, text or picture, additional content) component name.pack(side='position')
First, we fill in the corresponding content according to the corresponding information, and then we can locate the location information through pack. We can also use top and bottom location information.
This section briefly introduces the Tkinter module. In the next section, we will continue to learn its related controls.