我想在我的游戏中列出一个列表,所以我命名为Listbox,我已经导入了tkinter。当我运行代码时,控制台抛出了这个NameError: name 'ListBox' is not defined
所以我尝试了import tkinter as gui,ls = gui.Tk()和lsbox = gui.Listbox(ls)
我得到的是AttributeError: module 'tkinter' has no attribute 'ListBox'
那么我该如何修复这个错误呢?
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!")控制台:
= 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'
>>> 发布于 2019-08-25 11:22:15
这是Listbox,不是ListBox
import tkinter as tk
root = tk.Tk()
lbox = tk.Listbox(root, bg="yellow", fg="orange", selectbackground="grey")
lbox.pack()
root.mainloop()https://stackoverflow.com/questions/57642965
复制相似问题