tkinter yes Python Standards for GUI library , Tkinter modular (Tk Interface ) yes Python Standards for Tk GUI Interface to toolkit .Tk and Tkinter Can be in most of Unix Use under platform , It can also be applied to Windows and Macintosh In the system .Tk8.0 Later versions of can implement local window style , And works well on most platforms . So when you use it, just import That's all right. .
The code is as follows
import tkinter
import tkinter
# Create a window object
screen = tkinter.Tk()
# Use mainloop Method to make the window display
screen.mainloop()
The effect of the above code after execution is shown in the following figure
The interface is so dry that it doesn't look good , So we need to make a basic layout of our interface , before this , We need to learn some controls , And how to make them show
For the front-end partners, this label is very familiar , This is an ordinary text display , Let's see how it is realized here
The code is as follows
import tkinter
# Create a window object
screen = tkinter.Tk()
# establish label object
label = tkinter.Label(screen,text=" This is a label Control ")
# Show label,pack The function is adaptive
label.pack()
# Use mainloop Method to make the window display
screen.mainloop()
The effect is shown in the figure
This is an input box control , Like the front end text type , How is this achieved , Don't talk much , Code up
import tkinter
# Create a window object
screen = tkinter.Tk()
# establish label object
label = tkinter.Label(screen,text=" This is a label Control ")
# Show label,pack The function is adaptive
label.pack()
# The following three lines of code are generally connected , The first line is to set and get the input data
u = tkinter.StringVar()
text = tkinter.Entry(screen, textvariable=u)
text.pack()
# Use mainloop Method to make the window display
screen.mainloop()
The effect is shown below
Let's set the value in the input box first , Then get
import tkinter
# Create a window object
screen = tkinter.Tk()
# establish label object
label = tkinter.Label(screen,text=" This is a label Control ")
# Show label,pack The function is adaptive
label.pack()
# The following three lines of code are generally connected , The first line is to set and get the input data
u = tkinter.StringVar()
text = tkinter.Entry(screen, textvariable=u)
text.pack()
u.set("hello")
print(u.get())
# Use mainloop Method to make the window display
screen.mainloop()
The effect is shown in the figure
This control is the button , Some functions can be realized by clicking , What about this button How to add it , And how to realize the functions inside , Come on code
import tkinter
# Create a window object
screen = tkinter.Tk()
# establish label object
label = tkinter.Label(screen,text=" This is a label Control ")
# Show label,pack The function is adaptive
label.pack()
# The following three lines of code are generally connected , The first line is to set and get the input data
u = tkinter.StringVar()
text = tkinter.Entry(screen, textvariable=u)
text.pack()
u.set("hello")
def run():
print(u.get())
# among commend The value of is the function name
button = tkinter.Button(screen, text=" Am I ", command=run)
button.pack()
# Use mainloop Method to make the window display
screen.mainloop()
The effect is as shown in the picture
That's all tkinter Explain some basic parts of , I believe you also have a certain understanding , Then the next article will update the intermediate part !