Python Forum
How to dynamically change radiobutton text - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: How to dynamically change radiobutton text (/thread-32774.html)



How to dynamically change radiobutton text - kenwatts275 - Mar-04-2021

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()



RE: How to dynamically change radiobutton text - BashBedlam - Mar-05-2021

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



RE: How to dynamically change radiobutton text - deanhystad - Mar-05-2021

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.