Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

tkinter radiobutton value no pass to label, remain at initial value

I try to display the current variable for the radio button but it seems remain at the initial value which is zero.

my code was as below:

single_magnet_plot_style=IntVar(value=0)

Radio Button variable assignment:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

scatter_rbtn=Radiobutton(window, text="Scatter Plot", variable=single_magnet_plot_style,value=1)
scatter_rbtn.place(relx=0.4,y=600)
        
line_rbtn=Radiobutton(window, text="Line Plot", variable=single_magnet_plot_style,value=2)
line_rbtn.place(relx=0.6, y=600)

label display:

new_label=Label(window, text=single_magnet_plot_style.get(), fg='red', font=("Helvetica", 13))
new_label.place(relx=0.5, y=550,anchor=CENTER)

at my window, the label constantly stay at value 0.

enter image description here

Any advice to return the new_label from the radio button value ?

>Solution :

You need to use option textvariable instead of text if you want the label be updated whenever the selection of radiobuttons is changed:

new_label=Label(window, textvariable=single_magnet_plot_style, fg='red', font=("Helvetica", 13))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading