Python Forum
How to dynamically change radiobutton text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to dynamically change radiobutton text
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,

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

def main_program():
	btn['text']="Go pressed"

mw = Tk()

frame1 = Frame(mw)
frame2 = Frame(mw)
framebot = Frame(mw)

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

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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 tkinter radiobutton problem Nick_tkinter 14 1,085 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  [Tkinter] RadioButton Maryan 2 523 Oct-23-2020, 09:36 PM
Last Post: Maryan
  [PyQt] Increase text size and change color based on temp pav1983 5 859 Jun-22-2020, 10:52 PM
Last Post: menator01
  [Tkinter] How do I change an image dynamically LeeMadeux 7 18,686 Jun-04-2020, 10:00 PM
Last Post: deanhystad
  [Tkinter] How to create radiobutton in numpy gui python? luthfidali 2 1,020 May-23-2020, 10:35 AM
Last Post: timo
  [Tkinter] Python 3 change label text gw1500se 6 1,679 May-08-2020, 05:47 PM
Last Post: deanhystad
  Tkinter: increasing numbers and Radiobutton issue PeroPuri 1 688 Apr-13-2020, 05:48 PM
Last Post: deanhystad
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 5,981 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [PyQt] how to deselect radiobutton in pyqt5 atlass218 3 5,232 Oct-23-2019, 03:25 PM
Last Post: Denni
  Can't change the colour of Tk button text Pilover 4 7,242 Feb-27-2019, 09:02 PM
Last Post: Pilover

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020