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
  Can't change the colour of Tk button text Pilover 6 14,505 Nov-15-2022, 10:11 PM
Last Post: woooee
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 4,765 Aug-23-2022, 09:11 PM
Last Post: Extra
  tkinter change the text of the checkbox zazas321 1 3,759 Sep-17-2021, 06:19 AM
Last Post: zazas321
  Python3 tkinter radiobutton problem Nick_tkinter 14 5,835 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  [Tkinter] RadioButton Maryan 2 2,131 Oct-23-2020, 09:36 PM
Last Post: Maryan
  [PyQt] Increase text size and change color based on temp pav1983 5 3,097 Jun-22-2020, 10:52 PM
Last Post: menator01
  [Tkinter] How do I change an image dynamically LeeMadeux 7 31,759 Jun-04-2020, 10:00 PM
Last Post: deanhystad
  [Tkinter] How to create radiobutton in numpy gui python? luthfidali 2 2,570 May-23-2020, 10:35 AM
Last Post: timo
  [Tkinter] Python 3 change label text gw1500se 6 4,605 May-08-2020, 05:47 PM
Last Post: deanhystad
  Tkinter: increasing numbers and Radiobutton issue PeroPuri 1 2,120 Apr-13-2020, 05:48 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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