I am learning about the Tkinter library, but my code is giving this error"'type' Object is not subscriptable"

Asked

Viewed 21 times

0

def bt_click(botao):
    print(botao["text"])

janela = Tk()

bt1 = Button(janela, width=20, text= "botão 1")
bt1["command"]= partial(bt_click, bt1)
bt1.place(x=100, y=100)

bt2 = Button(janela, width=20, text="botão 2")
bt2["command"] = partial[bt_click, bt2]
bt2.place(x=200, y=200)

janela.geometry("300x300+200+200")
janela.mainloop()
  • 1

    Your code is missing "import". It would be interesting to edit your reply and add the full error message.

  • Where are you setting partial. Is it a function? Complement with the minimum code for reproduction

1 answer

0

The mistake seems to be on this line:

bt2["command"] = partial[bt_click, bt2]

You are using as if it were a dictionary (of two keys?), while on the first occasion you called as a function. Switch to

bt2["command"] = partial(bt_click, bt2)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.