Tkinter使用Listbox获取

2024-07-03 04:27:24 发布

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

我试图使用Listbox函数允许用户在我编写的程序中为x和y轴选择一个选项。我一直收到这个错误:

Traceback (most recent call last):
  File "tkkkk2.py", line 72, in <module>
    my_gui = MyFirstGUI(root)
  File "tkkkk2.py", line 51, in __init__
    listbox = Listbox(master)
NameError: global name 'Listbox' is not defined

代码如下:

^{pr2}$

Tags: 函数用户inpy程序most选项错误
1条回答
网友
1楼 · 发布于 2024-07-03 04:27:24

错误告诉您Listbox未定义。你没有在任何地方导入它,也没有在任何地方定义它。在

这是大多数人建议一次进口所有Tkinter的一个很好的理由:

import Tkinter as tk
...
root = tk.Tk()
...
listbox = tk.Listbox(master)
...

相关问题 更多 >