Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a tkinter error message box [duplicate]

I am wanting to create a simple message box in Tkinter that appears and displays the exact error message. Could anyone direct me to how this might be achieved in tkinter, I have not been able to find much on this topic.

E.g:

traceback.format_exc().replace(':', '-')
ctypes.windll.user32.MessageBoxW(0, "Error", "Have you checked your fridge?"d, 1)
                                                             ^
#'SyntaxError: invalid syntax'

I am wanting to add this with pyinstaller. I suppose pyinstaller creates a text file and you can see in cmd before it closes, but it would be nice if a message box appear with exact traceerror.


2 Answers

from tkinter import messagebox

messagebox.showerror("Title", "Message")

check here for more info

like image 71
Roars Avatar answered Oct 29 '25 03:10

Roars


This login system which will pop up messagebox when you provide wrong data for entry messagebox should be entered into the entry if not the messagebox will pop up prompting you an error as occured

from tkinter import *
from tkinter import messagebox


def top():
    if entry1.get() == "messagebox":
       log.destroy()
       root.deiconify()
    else:
       messagebox.showerror("error", "try again")
       messagebox.showinfo("my message","this is an example of showinfo\nmessagebox")
       messagebox.showwarning("warning", "show warning example in tkinter" ) 


root = Tk()
root.geometry("400x400")

log = Toplevel(root)
log.geometry("200x200")


label1 = Label(log, text="password")
entry1 = Entry(log)
button1 = Button(log, text="login", command=top)

label1.pack()
entry1.pack()
button1.pack(side="bottom")

lab = Label(root, text="welcome bro").pack()


root.withdraw()
root.mainloop()
like image 41
AD WAN Avatar answered Oct 29 '25 03:10

AD WAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!