Python Forum
[Tkinter] Default Values for radiobuttons - Printable Version

+- Python Forum (
+-- Forum: Python Coding (
+--- Forum: GUI (
+--- Thread: [Tkinter] Default Values for radiobuttons (/thread-26876.html)

Default Values for radiobuttons - xuraax - May-17-2020

I am learning to use tkinter and I have a program which includes Radiobuttons and Entry. These work well if I press buttons and insert text into the appropriate widgets each time I start the program.

I would like to alter the program to use default values at startup so that then all I have to do is press continue if I want to stay with the defaults. From documentation I understood that this can be done using .invoke() for the radiobuttons but when I run this i get the following error at this strip of code:

   # radio button
    button_var = IntVar()
    radio_1 = Radiobutton(
        text="Windows", variable=button_var, value=1).place(x=15, y=338)
    radio_2 = Radiobutton(text="Linux", variable=button_var,
                          value=2).place(x=115, y=338)
>>> AttributeError: 'NoneType' object has no attribute 'invoke'
My intention if for the program to default to the "Linux" option.

Can anyone help please?

RE: Default Values for radiobuttons - menator01 - May-17-2020

Please use tags when posting code.
This works for me.

move the .place to and

import tkinter as tk

root = tk.Tk()

var = tk.IntVar()
r1 = tk.Radiobutton(root, text='Option 1', variable=var, value=1)

r2 = tk.Radiobutton(root, text='Option 2', variable=var, value=2)

r3 = tk.Radiobutton(root, text='Option 3', variable=var, value=3)


RE: Default Values for radiobuttons - xuraax - May-17-2020

Thank you for your suggestion and I apologise for not using the tag option. Will do so in the future.

Moving the
to its own line as you suggest worked perfectly