I made a calculator with tkinter(obviously in python) and it is meant to ask for user input, and depending on the input, show a result on the screen. However, it doesnt wait for input and just prints the result instead!
Heres the code:
#import modulesimport tkinter as tkimport osimport timewindow = tk.Tk()end = window.mainloopheader= tk.Label( text = "Calculator", fg = "black", bg = "white",)header.pack()entry = tk.Entry()label = tk.Label(text="Enter your first number:")label.pack()entry.pack()ans1 = entry.get()time.sleep(1)label2 = tk.Label(text="Enter your second number:")label2.pack()entry2 = tk.Entry()entry2.pack()ans2 = entry2.get()time.sleep(1)label3 = tk.Label(text="Enter your operator:")label3.pack()entry3 = tk.Entry()entry3.pack()ans3 = entry3.get()time.sleep(10)if ans3 == "add": result = ans1 + ans2elif ans3 == "sub": result = ans1 - ans2elif ans3 == "mul": result = ans1 * ans2elif ans3 == "div": result = ans1 / ans2elif ans3 == "mod": result = ans1 % ans2elif ans3 == "pow": result = ans1 ** ans2else: result = "error"label4 = tk.Label(text="The result is:")label4.pack()label5 = tk.Label(text=result)label5.pack()end()I made a calculator with tkinter(obviously in python) and it is meant to ask for user input, and depending on the input, show a result on the screen. However, it doesnt wait for input and just prints the result instead!
Heres the code:
#import modulesimport tkinter as tkimport osimport timewindow = tk.Tk()end = window.mainloopheader= tk.Label( text = "Calculator", fg = "black", bg = "white",)header.pack()entry = tk.Entry()label = tk.Label(text="Enter your first number:")label.pack()entry.pack()ans1 = entry.get()time.sleep(1)label2 = tk.Label(text="Enter your second number:")label2.pack()entry2 = tk.Entry()entry2.pack()ans2 = entry2.get()time.sleep(1)label3 = tk.Label(text="Enter your operator:")label3.pack()entry3 = tk.Entry()entry3.pack()ans3 = entry3.get()time.sleep(10)if ans3 == "add": result = ans1 + ans2elif ans3 == "sub": result = ans1 - ans2elif ans3 == "mul": result = ans1 * ans2elif ans3 == "div": result = ans1 / ans2elif ans3 == "mod": result = ans1 % ans2elif ans3 == "pow": result = ans1 ** ans2else: result = "error"label4 = tk.Label(text="The result is:")label4.pack()label5 = tk.Label(text=result)label5.pack()end()I have tried using time.sleep()to make it wait for input and then show the result. but it just waits before opening the program GUI.