tkinter+radiobutton
时间: 2023-12-26 16:28:39 浏览: 138
以下是一个使用tkinter库创建一个包含Radiobutton的GUI窗口的示例:
```python
import tkinter as tk
def show_selection():
selection = var.get()
if selection == 1:
label.config(text="You selected Option 1")
elif selection == 2:
label.config(text="You selected Option 2")
elif selection == 3:
label.config(text="You selected Option 3")
root = tk.Tk()
root.title("Radiobutton Example")
var = tk.IntVar()
radio_button1 = tk.Radiobutton(root, text="Option 1", variable=var, value=1, command=show_selection)
radio_button1.pack()
radio_button2 = tk.Radiobutton(root, text="Option 2", variable=var, value=2, command=show_selection)
radio_button2.pack()
radio_button3 = tk.Radiobutton(root, text="Option 3", variable=var, value=3, command=show_selection)
radio_button3.pack()
label = tk.Label(root, text="")
label.pack()
root.mainloop()
```
这个例子创建了一个GUI窗口,其中包含三个Radiobutton选项。当用户选择一个选项时,会调用`show_selection`函数来更新一个Label的文本,显示用户选择的选项。
阅读全文