I am trying to keep a record of transactions into an excel file. The user is able to enter text via a textbox that I created using tkinter.
Here is a simplified version of my code.
quantity = '0'
newWindow = Tk()
buyLabel = Label(newWindow, text = 'How many apples do you want to buy?')
global textentry2
textentry2 = Entry(newWindow, width=10)
global quantity
if quantity=="":
quantity=0
quantity = textentry2.get()
quantity = int(float(quantity))
I want my program to check if the value the user enters is acceptable. For the number of apples they buy, they should return an int bigger than 0. Therefore, return TRUE if the text entered in 'textentry2' is an int and bigger than 0 and FALSE if it isn't an int or smaller than zero. However, I do not know how to check if the entered text is an int, so I tried to convert it to an int first then just check if it is > 0. HERE IS MY CODE:
if (quantity > 0):
print('your value is stored')
else:
print('please enter an acceptable quantity')
I got an error that said invalid literal for int() with base 10: ' ' and from another post in stackoverflow, they said to convert the variable to float, then int, and this is why my code looks like this:
quantity = int(float(quantity))
however, I still get an error 'ValueError: could not convert string to float:' I AM CONFUSED. can anyone help? It would also be great if you know how to check if the entered text is an int.