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")
CodePudding user response:
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()