With python GUI creation library "tkinter" I was in trouble because I didn't know how to write the process that the label was rewritten when the button was pressed.
I will write the coping method according to the original purpose and content of creating an application that receives the numerical value entered in the text box and outputs the average.
Python 3.6.8
When rewriting the label of the variable name words as "rewrited" In the process when the button is pressed
words["text"] = "rewrited"
Just add it.
import tkinter as tk
root = tk.Tk()
root.title(u"Average calculation app")
root.geometry("400x300")
#Processing when the button is pressed
def buttoneffect(event):
value = textbox.get()
split_value = value.split(",")
int_values = list(map(int, split_value))
average = sum(int_values) / len(int_values)
textbox.delete(0, tk.END) #Initialize the contents of the text box
words4["text"] = "The average value is%s." % average #Rewrite the contents of the label
#Arrangement of buttons and text boxes
words = tk.Label(text=u"Calculates the average value of the entered values.", font=("", 12))
words.pack()
words2 = tk.Label(text=u"Enter the numbers separated by commas.", font=("", 12))
words2.pack()
textbox = tk.Entry()
textbox.insert(tk.END, "Input this box.")
textbox.place(x=140, y=70)
button = tk.Button(text=u"calculate")
button.bind("<Button-1>", buttoneffect)
button.place(x=150, y=100)
words3 = tk.Label(text=u"Statistical data", font=("", 12))
words3.place(x=50, y=140)
words4 = tk.Label(text=u" ", font=("", 12)) #Empty label used to output mean
words4.place(x=140, y=160)
root.mainloop()
Try using Python's Tkinter https://qiita.com/nnahito/items/ad1428a30738b3d93762
How to change Tkinter label text https://www.delftstack.com/ja/howto/python-tkinter/how-to-change-the-tkinter-label-text/
Recommended Posts