Help with Python tkinter error

Question:
How to fix attribute error


Repl link:
https://replit.com/@Obiben27/Adventrue-turn-based-game-2D#main.py

def attack():  # options on how to attack
   global button1, button2, button3, label1, label2, label3
   button1.forget()
   label2.forget()
   button2.forget()
   button3.forget()
   label2.configure(window, text="What attack do you want to do?")
   button1.configure(
      window, text="heavy attack", command=lambda start=True: heavy_attack()
   )
   button2.configure(
      window, text="light attack", command=lambda start=True: light_attack()
   )
   button3.configure(
      window, text="return", command=lambda start=True: combat()
   )
   label2.pack()
   button1.pack()
   button2.pack()
   button3.pack()

(not the best at programming) When I run the code I get
Traceback (most recent call last): aw
File "main.py”, line 68, in <module>
attack()
File "main.py”, line 55, in attack
label2.configure(window, text="what attack do you want to do?")
File "/nix/store/2vm88xw7513h9pyjyafw32cps51boial-python3-3.8.12/1ib/python3.8
/tkinter/__init__.py", line 1646, in configure
return self._configure( configure’, cnf, kw)
File "/nix/store/2vm88xw7513h9py]jyafw32cps51b0ial-python3-3.8.12/1ib/python3.8
/tkinter/__init__.py", line 1636, in configure
self.tk.call(_flatten((self. w, cnd)) + self. options(cnf))
Kinter.TclError: unknown option "-class”

as an error

You’re trying to use a .configure method on your label with an incorrect argument

.configure method is used to change the attributes of a Tkinter object like a label, button, etc.

In your case, if you want to change the text of label2 , you should do:

label2.configure(text="What attack do you want to do?")

And your code will look like this:

def attack():  # options on how to attack
    global button1, button2, button3, label1, label2, label3
    button1.forget()
    label2.forget()
    button2.forget()
    button3.forget()
    label2.configure(window, text="What attack do you want to do?")
    button1.configure(
        window, text="heavy attack", command=lambda start=True: heavy_attack()
    )
    button2.configure(
        window, text="light attack", command=lambda start=True: light_attack()
    )
    button3.configure(window, text="return", command=lambda start=True: combat())
    label2.pack()
    button1.pack()
    button2.pack()
    button3.pack()
2 Likes

Thank you so much. Not that good at tkinter yet

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.