B
B
barbedman2016-05-23 21:44:32
Python
barbedman, 2016-05-23 21:44:32

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())

But in this scenario, the program simply ends after 5 seconds and nothing more, but if you replace exit with quit, then nothing happens.
Tell me what can be done about it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Senka Chekanov, 2016-07-25
@Sencho_Pens

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 question

Ask a Question

731 491 924 answers to any question