New to GUI's in Python and using Tkinter. Trying to get a format check validation to work in an entry box (want to allow float's only). Returns this error tkinter.TclError: expected floating-point number but got "0.0fhdhdfhdf"
and tkinter message box does not display.
I declared the variables earlier in the code as DoubleVar
. I know it's a data type issue but have tried everything. Any ideas appreciated?
#3 x variables declared
value0 = StringVar()
convert = DoubleVar()
currency = DoubleVar()
#This is the boolean currency converter defining the ConCurency method which calls the variable value0 and speeding up conversion of the float using parallel program with the get and set class for the value of USD/JPY/EUR
max_input = 50000
min_input = 10
def ConCurrency(): #performing the conversion #credit to https://www.youtube.com/channel/UCI0vQvr9aFn27yR6Ej6n5UA This was a you tube video, that I found and have changed to suit my needs.
if value0.get() == "USD":
convert1 = float(convert.get() *1.34)
convert2 = "USD", str('%.2f' %(convert1))
currency.set(convert2)
elif value0.get() == "JPY":
convert1 = float(convert.get() *146.4131)
convert2 = "JPY", str('%.2f' %(convert1))
currency.set(convert2)
elif value0.get() == "EUR":
convert1 = float(convert.get() *1.1300)
convert2 = "EUR", str('%.2f' %(convert1))
currency.set(convert2)
# defining the Reset value for the original value0 using the set class.
def Reset():
value0.set("")
convert.set("0.0")
currency.set("0.0")
#Entry Widget - to create the input space for the user to add their amount of GBP.
ent_Currency=Entry(MainFrame,font=('PlayFairDisplay'), textvariable=convert, bd=2,width=28, justify='center')
ent_Currency.grid(row=0,column=1)
def validate(convert):
if convert.isdigit:
return True
tkinter.messagebox.showinfo("Correct Data","That is a valid input")
else:
False
currency.set("")
tkinter.messagebox.showwarning("Wrong Data", "Numbers Only")