+ 1
I am having error in my Calculator, and I'm not getting output
import tkinter window=tkinter.Tk() window.title('Calculator') window.geometry("500x600") l1=tkinter.Label(window, text="Calculator", font=("Arial", 10), bg='red', fg='white') l2=tkinter.Label(window, text="Input what you want to calculate here", font=('Arial', 6), bg='blue', fg='white').grid(row=2, column=2) def cal(): x=en1.get() print(x) en1=tkinter.Entry(window, justify="center", width=10).grid(row=3, column=2) y=tkinter.IntVar() y.set() l3=tkinter.Label(window, textvariable=y, text=" ").grid(row=4, column=2) b1=tkinter.Button(window, text="Calculate", bg="blue", fg="white", command=cal).grid(row=5, column=2) window.mainloop()
4 Antworten
+ 3
To Bi, it’s not a typing error as mentioned. The issue you have is a missing argument:
y.set() # should be: —-> y.set('test’)
needs an argument, what the associated object expected. It has to be a string.
After this the code will run.
0
Okay, will do that.
Thanks
0
Thanks, I tried that buh it give me error "object has no attribute" here is the new code.
import tkinter
window=tkinter.Tk()
window.title('Calculator')
window.geometry("500x600")
l1=tkinter.Label(window, text="Calculator", font=("Arial", 10), bg='red', fg='white')
l2=tkinter.Label(window, text="Input what you want to calculate here", font=('Arial', 6), bg='blue', fg='white').pack()
x=tkinter.IntVar()
x.set("2+2")
en1=tkinter.Entry(window, textvariable=x, justify="center", width=10).pack()
y=tkinter.IntVar()
y.set('test')
l3=tkinter.Label(window, textvariable=y, text=" ").pack()
def cal():
l3.configure(text=eval(x.get))
b1=tkinter.Button(window, text="Calculate", bg="blue", fg="white", command=cal).pack()
window.mainloop()