Python Forum

Full Version: How to dynamically change radiobutton text
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everybody.
I am trying to dynamically change the text of a radio button.
Below is an example program. When you run it, when you click on the "Go" button, the text of the radiobutton is supposed to change.
When I run it, I get the error "NoneType" object does not support item assignment.
Any help would be appreciated.
Thanks in advance,
Ken


from tkinter import *
from tkinter import filedialog
import tkinter.font as font

def main_program():
	btn['text']="Go pressed"
	print("Finished\n")

mw = Tk()
mw.geometry('700x300+400+200')

frame1 = Frame(mw)
frame2 = Frame(mw)
framebot = Frame(mw)
frame1.pack(side=TOP,fill=X)
frame2.pack(side=TOP,fill=X)
framebot.pack(side=BOTTOM,fill=X)

btn = Radiobutton(frame2,text='Press Go',font=("Times",16)).pack(side="left")

btn3 = Button(framebot,text='Go',font=("Times",16),command=main_program).pack(side="left")
btn4 = Button(framebot,text='Exit',font=("Times",16),command=mw.quit).pack(side="right")

mw.mainloop()
Believe it or not, in order for that to work you will have to put pack on a separate line. I have no idea why Huh

btn = Radiobutton(frame2,text='Press Go',font=("Times",16))
btn.pack(side="left")
Because the pack() method returns None, like any function or method without a return. I think most methods/functions return None. No real statistics, just a hunch.