gpt4 book ai didi

python - 名称错误 : global name 'messagebox' is not defined - CONSOLE MODE

转载 作者:太空宇宙 更新时间:2023-11-04 10:18:12 25 4
gpt4 key购买 nike

我导入了 tkinter.messagebox,当我按 F5 并在 IDLE 上测试时,我的程序运行顺利。但是,当应该显示消息框时,我的程序没有在控制台上运行,并且出现错误:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\lib\tkinter\__init__.py", line 1456, in __call__
return self.func(*args)
File "U:\my documents\6th form\A2\Computing\F454\Code and Prototyping\trackeve
nts.py", line 204, in validation
messagebox.showerror("Data invalid", "The data you have entered is invalid.
Please make sure you have submitted it correctly.")
NameError: global name 'messagebox' is not defined

如果需要,我导入消息框和代码部分:

import tkinter.messagebox

def validation():
(...)
elif completedValidation == False:
messagebox.showerror("Data invalid", "The data you have entered is invalid. Please make sure you have submitted it correctly.")

最佳答案

如果您import tkinter.messagebox,您必须这样引用它:with tkinter.messagebox。如果你只想将它别名为 messagebox,你需要 from tkinter import messagebox

关于python - 名称错误 : global name 'messagebox' is not defined - CONSOLE MODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34063335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com