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

Make Radio Button on Menubar Dropdown selected by Default (tkinter Python)

I want the "Basic" option to be selected by default. How can I do this?

from tkinter import *
windowMenu = Menu(menubar,tearoff=0)
menubar.add_cascade(label="Window",menu=windowMenu)
windowMenu.add_radiobutton(label="Basic")
windowMenu.add_radiobutton(label="Extended")

>Solution :

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

You must associate a variable with the entries, define a value for each radiobutton, and then set the variable to the appropriate value.

from tkinter import *
root = Tk()
menubar = Menu(root)
root.configure(menu=menubar)

windowMenu = Menu(menubar,tearoff=0)
menubar.add_cascade(label="Window",menu=windowMenu)
var = StringVar(value="Basic")
windowMenu.add_radiobutton(label="Basic", variable=var)
windowMenu.add_radiobutton(label="Extended", variable=var)

root.mainloop()
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