我要的是"Basic"默认情况下要选择的选项。我该怎么做呢?
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")
您必须将变量与条目关联,为每个单选按钮定义一个值,然后将变量设置为适当的值。
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()