I want to try exception in tkinter. If I do not input anything into entry, it will raise ValueError and the messagebox will pop up. However, when I run my code, it indeed can catch exception, but no messagebox pops up. Can anyone tells me reason and how to correct it? Thank you.
from tkinter import *
from tkinter import messagebox
try:
root = Tk()
def function():
if not entry_test.get():
raise ValueError
Label(root, text = entry_test.get()).grid()
entry_test = Entry(root)
entry_test.grid()
button_click = Button(root, text ="click to test", command= function)
button_click.grid()
root.mainloop()
except ValueError:
message.showwarning("ENTRY ERROR", "please input somthing in entry")