window = tk. Tk() #creates a new window
age = StringVar()
window.title("Are you old enough to smoke?") #title
window.geometry("300x200") #window size
window.wm_iconbitmap('favicon.ico') #icon
photo = tk.PhotoImage(file="images.png") #picture in said window
w = tk.Label(window, image=photo)
w.pack()
lbl=tk.Label(window, text="Please enter your age.", bg="light salmon", fg="blue2") #label text & color
lbl.pack()
ent = tk.Entry(window, text="(Your age here)", textvariable=age)
ent.pack()
def callback():
ageint = int(age.get())
#Line causing error RIP^
if ageint >= 18:
mess = 'You are legally able to smoke cigarettes.'
elif ageint <= 12:
mess = "You're to young to smoke,\nGet out of here."
else:
mess = "You are not of legal age to smoke."
if ageint >= 21:
mess += "\nYou are legally able to smoke marijuana."
if ageint >= 40:
mess += "\nYou're above the age of forty,\nDo you really need to ask
messagebox.showinfo(title="Can you Smoke", message=mess)
btn = tk.Button(window, text="Confirm", bg="sienna1", fg="blue2", relief="groove", command=callback)
btn.pack()
There is my code. Every thing works great when I run my program (very simple little practice thing) it sometimes work and displays the correct message. but sometimes my messagebox does not show up and this error appears in the console:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:/Users/Josh/Documents/Trial Python Programs/Smoke window Program.py", line 22, in callback
ageint = int(age.get(), base=3)
ValueError: invalid literal for int() with base 10: ''
I have found many topics relating to the issue, but none that specifically help me (or atleast that I understand). I am just confused because sometimes it happens and sometimes it does not. Any help/tips would be greatly appreciated.
Background info:
Python34
Win7-64 bit
I've been doing this for less than a week go easy on me please.
I only provided the amount of code that I thought was needed.