I started using python and knew that I could do various things. I've used it from the command prompt, but can I also use a GUI for input / output tools? First of all, I made a sample for myself.
Searching for "tkinter", "GUI", and "text box" will hit some sites, but suddenly the calculator is running, there is only a part of the explanation for the first time to use tkinter, input only / output Because it was only, I wrote only the part to input and display, which is the basis of the basics
First of all, it worked, so I will record it as a memorandum for myself I will add an explanation as soon as possible </ font> If you can do so far, you can add what you wrote in CUI, enter the search key, and display the result on the GUI as usual, so you can rest assured.
Either pressing the Enter key or clicking the button will display the entered characters on the output label (the part that initially displays "Output Data"). When actually using it, I think it will be either func or calc
import os, tkinter
def func(): #Operation when the Enter key is pressed
getvalue = textBox1.get()
print("in the function =",getvalue)
textBox1.delete(0,tkinter.END)
label2["text"] = getvalue
def calc(event): #Operation when the button is pressed
getvalue = textBox1.get()
print("in the function =",getvalue)
textBox1.delete(0,tkinter.END)
label2["text"] = getvalue
#Window
root = tkinter.Tk() #Tk class generation
root.title(u"Window title") #Screen title
root.geometry("350x150") #Screen size
#Input / output area
label1 = tkinter.Label(text='InputData') #Input label
label1.place(x=5,y=5) #Label display position
textBox1 = tkinter.Entry(width=5) #Text box for input
textBox1.place(x=100, y=5) #Text box position specification
label2 = tkinter.Label(text='OutputData') #Output label
label2.place(x=100,y=50) #Label position
textBox1.focus_set() #Specify focus on text box
btn = tkinter.Button(text='Go', command=func) #Button creation
btn.pack()
textBox1.bind('<Return>', calc) #Press Enter to set event
root.mainloop() #Show screen
Recommended Posts