Answer the question
In order to leave comments, you need to log in
How to exit a program with an error message in Tkinter?
Good evening everyone. Recently asked to implement a program with a graphical interface. For this, I used the Tkinter library. For full-fledged work, I wanted to make a normal program reaction to various errors, i.e. if an error occurs, a message is displayed on the screen, and then the program closes. I implemented it this way:
if (summToPay >= maxPayment):
log.after(0, print_error('You have exceeded the maximum payment amount\n'))
root.after(5000, exit())
Answer the question
In order to leave comments, you need to log in
There are dialog libraries for such needs, if you want it to come out as a typical error message, then this will help you:
from tkinter import messagebox
root = Tk()
...
if summToPay >= maxPayment:
messagebox.showerror('Error!' , 'You have exceeded the maximum payment amount\n')
exit() or root.destroy()
If you want a typical warning, replace showerror with showwarning.
PS Read Lutz, "Python Programming"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question