Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does Python convert the contents of the string entered in the tkinter input box into an integer type?
How does Python convert the contents of the string entered in the tkinter input box into an integer type?
Set the variable type and convert it after receiving the input, as follows:

Import tkinter

windows = tkinter。 Tk()? # Instantiate the window class

Windows.title ('demo')? # Window title

Def sub(): # Create an addition function

number 1 = int(ent 1 . get())? # Convert the contents of two buttons to string type.

number2 = int(ent2.get())

Number 3 = number 1+number 2

Variable set (number 3)

var = tkinter。 IntVar()? # Define variable types

ent 1 = tkinter。 Getting started (windows)?

ent2 = tkinter。 Entries (windows)

ent3 = tkinter。 Entry (windows, textvariable=var)

ent 1.pack(side = tkinter。 Left, padx=5)? # Line break positioning control

ent2.pack(side = tkinter。 Left, padx=5)

ent3.pack(side = tkinter。 Left, padx=5)

button 1 = tkinter . button(Windows,text =' calculation ',command = sub)。 pack()? # Binding signal

Button 2 = tkinter.button (Windows,text =' exit ',command = windows.destroy)。 Pack ().

windows.mainloop()? # Loop to keep the window running