tkinter radiobutton实例
时间: 2023-11-18 20:05:11 浏览: 89
以下是一个tkinter Radiobutton的实例:
```python
import tkinter as tk
window = tk.Tk()
window.title("Radiobutton Example")
var = tk.StringVar()
var.set("Option 1")
def print_selection():
label.config(text="You have selected " + var.get())
rb1 = tk.Radiobutton(window, text="Option 1", variable=var, value="Option 1", command=print_selection)
rb1.pack()
rb2 = tk.Radiobutton(window, text="Option 2", variable=var, value="Option 2", command=print_selection)
rb2.pack()
rb3 = tk.Radiobutton(window, text="Option 3", variable=var, value="Option 3", command=print_selection)
rb3.pack()
label = tk.Label(window, text="")
label.pack()
window.mainloop()
```
这个例子创建了一个窗口,其中包含三个Radiobutton选项,当用户选择其中一个选项时,程序会在窗口中显示所选选项的文本。
阅读全文