so I know how entry in python works and i coded it in some projects. but in one project , there was need to get numeric ( number ) value from user in entry. but it gives the error that entry only supports string data. can you solve this problem ? thanks.
CodePudding user response:
You just need to typecast it into an integer. Eg. This code worked for me:
from tkinter import *
win=Tk()
win.geometry("700x350")
def cal_sum():
t1=int(a.get()) # Casting to integer
t2=int(b.get()) # Casting to integer
sum=t1 t2
label.config(text=sum)
Label(win, text="Enter First Number", font=('Calibri 10')).pack()
a=Entry(win, width=35)
a.pack()
Label(win, text="Enter Second Number", font=('Calibri 10')).pack()
b=Entry(win, width=35)
b.pack()
label=Label(win, text="Total Sum : ", font=('Calibri 15'))
label.pack(pady=20)
Button(win, text="Calculate Sum", command=cal_sum).pack()
win.mainloop()