首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Python 3中调用列表框时出现属性错误

在Python 3中调用列表框时出现属性错误
EN

Stack Overflow用户
提问于 2019-08-25 11:15:24
回答 1查看 116关注 0票数 0

我想在我的游戏中列出一个列表,所以我命名为Listbox,我已经导入了tkinter。当我运行代码时,控制台抛出了这个NameError: name 'ListBox' is not defined

所以我尝试了import tkinter as guils = gui.Tk()lsbox = gui.Listbox(ls)

我得到的是AttributeError: module 'tkinter' has no attribute 'ListBox'

那么我该如何修复这个错误呢?

代码语言:javascript
复制
from tkinter import *  
import tkinter as gui
from random import randint

#code open the first window

print("Listbox setup...", end="")
ls = Tk()
lsbox = ListBox(ls, bg="yellow", fg="orange", selectbackground="grey")
lsbox.pack()
print("OK!")

控制台:

代码语言:javascript
复制
= RESTART: /Volumes/GoogleDrive/My Drive/Testing TECH/python/hit-and-blow.py =
~~~===hit and blow===~~~
*important: install tkinter on your PC to make this work.*
mainwin setup...OK!
Listbox setup...Traceback (most recent call last):
  File "/Volumes/GoogleDrive/My Drive/Testing TECH/python/hit-and-blow.py", line 16, in <module>
    lsbox = gui.ListBox(ls, bg="yellow", fg="orange", selectbackground="grey")
AttributeError: module 'tkinter' has no attribute 'ListBox'
>>> 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-25 11:22:15

这是Listbox,不是ListBox

代码语言:javascript
复制
import tkinter as tk

root = tk.Tk()
lbox = tk.Listbox(root, bg="yellow", fg="orange", selectbackground="grey")
lbox.pack()

root.mainloop()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57642965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档