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
#1
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()
Reply
#2
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")
Reply
#3
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.
Reply


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

Forum Jump:

User Panel Messages

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