如何创建tkinter错误消息框

2024-05-13 08:40:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Tkinter中创建一个简单的消息框,它会出现并显示准确的错误消息。有人能告诉我这是怎么回事吗 在tkinter取得的成就,我在这个话题上找不到太多。

例如:

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

我想用pyinstaller添加这个。我想pyinstaller创建了一个文本文件,您可以在它关闭之前在cmd中看到它,但是如果出现一个带有确切traceerror的消息框就更好了。


Tags: format消息tkinter错误ctypesreplaceexc话题
2条回答

当您为条目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()
from tkinter import messagebox

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

查看here了解更多信息

相关问题 更多 >