How to create a tkinter error message box

27,862

Solution 1

from tkinter import messagebox

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

check here for more info

Solution 2

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()
Share:
27,862
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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.