如何创建tkinter错误消息框[重复]

问题描述 投票:0回答:2

这个问题在这里已有答案:

我想在Tkinter中创建一个简单的消息框,它出现并显示确切的错误消息。任何人都可以指导我如何在tkinter中实现这一点,我在这个主题上找不到多少。

E.g:

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

我想用pyinstaller添加它。我想pyinstaller会创建一个文本文件,你可以在它关闭之前在cmd中看到,但如果出现一个带有精确traceerror的消息框,那将会很好。

python python-3.x tkinter error-handling pyinstaller
2个回答
2
投票
from tkinter import messagebox

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

查看here了解更多信息


1
投票

当您为条目messagebox提供错误数据时将弹出消息框的登录系统应该输入到条目中,否则弹出消息框会提示您发生错误

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()
© www.soinside.com 2019 - 2024. All rights reserved.