user11141993
user11141993

Reputation:

Calling Listbox in Python 3 got an attribute error

I want to make a list in my game, so i called Listbox which i have already imported tkinter. and when i run the code, the console threw that NameError: name 'ListBox' is not defined

So i tried import tkinter as gui, ls = gui.Tk() and lsbox = gui.Listbox(ls)

and what i have got is AttributeError: module 'tkinter' has no attribute 'ListBox'

So how can I fix that error?

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!")

console:

= 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'
>>> 

Upvotes: 0

Views: 234

Answers (1)

Reblochon Masque
Reblochon Masque

Reputation: 36662

It is Listbox, not ListBox

import tkinter as tk

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

root.mainloop()

Upvotes: 1

Related Questions