-1

I am trying to change the text of a button with a click event, but am having trouble and have found no other solutions.

from Tkinter import *
root=Tk()
def buttonclick()
    oneButton["text"]="Bye"

OneButton = Button(root, text="hi", command = lambda: buttonclick()).grid (row=0, column =0, sticky=NSEW)

 root.mainloop()

With this method, I am getting:

TypeError: 'NoneType' object does not support item assignment

I have looked at oneButton.config(text="bye") and oneButton.configure(text="Bye") as well and with both. I learn that the button object does not have the attribute config or configure.

What am I doing wrong?

das-g
  • 9,718
  • 4
  • 38
  • 80
uncertaintea
  • 87
  • 2
  • 4
  • 10

1 Answers1

0

i fixed it using textvariable and stringvar().

 from Tkinter import *
 root=Tk()

 buttonText=StringVar()
 oneButton = Button(root, textvariable = buttonText, command = lambda: buttonText.set('bye')).grid (row=0, column =0, sticky=NSEW)
 buttonText.set('Hi')

 root.mainloop()
uncertaintea
  • 87
  • 2
  • 4
  • 10