我正在用 tkinter 设计一个 GUI。有三个单选按钮绑定到每个单独的框架。是否可以通过单击其中一个来禁用其他两个单选按钮?或者甚至更好地禁用其他两个框架
我无法实现此功能。下面是部分代码。如果您需要更多信息,请告诉我。谢谢
root = Tk()
root.title("MyApp")
f1 = ttk.Frame(root, padding="3 3 12 12")
f1.grid(row=0, sticky=(W, E, N, S))
Label(f1, text = "Welcome to My App!", font=("Times New Roman", 20)).grid(column=3, row=1, sticky='EW')
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
option = StringVar()
topframe=ttk.Frame(root, padding="3 3 12 12", relief = GROOVE, borderwidth = 10)
topframe.grid(row=1, sticky=(W, E, N, S))
mainframe = ttk.Frame(root, padding="3 3 12 12", relief = GROOVE, borderwidth = 10)
mainframe.grid(row=2, sticky=(W, E, N, S))
bottomframe = ttk.Frame(root, padding="3 3 12 12", relief = GROOVE, borderwidth = 10)
bottomframe.grid(row=3, sticky=(W, E, N, S))
paraframe = ttk.Frame(root, padding="3 3 12 12" , relief = GROOVE, borderwidth = 10)
paraframe.grid(row=4, sticky=(W, E, N, S))
rb1 = Radiobutton(topframe, text="Select Files", value="files", var=option)
rb1.grid(column=0, columnspan=2, row=0, sticky=W)
rb2 = Radiobutton(mainframe, text="Select a Directory", value="directory", var=option)
rb2.grid(column=0,columnspan=2, row=0,sticky=W)
rb3 = Radiobutton(bottomframe, text="Paste a JSON File", value="json", var=option)
rb3.grid(column=0,columnspan=2, row=0,sticky=W)
# function to gray out
def greyOutNotTop():
if option.get() == "files":
rb2.config(state='disable')
rb3.config(state='disable')
def greyOutNotMain():
if option.get() == "directory":
rb1.config(state='disable')
rb3.config(state='disable')
def greyOutNotBottom():
if option.get() == "json":
rb1.config(state='disable')
rb2.config(state='disable')
root.mainloop()