📜  gui单选按钮python代码示例

📅  最后修改于: 2022-03-11 14:46:44.901000             🧑  作者: Mango

代码示例1
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import askyesno, askquestion




def selected():
    print(confirmed.get())


root = tk.Tk()

confirmed = tk.StringVar() #used to get the 'value' property of a tkinter.Radiobutton

# Note that I added a command to each radio button and a different 'value'
# When you press a radio button, its corresponding 'command' is called.
# In this case, I am linking both radio buttons to the same command: 'selected'

rconfirmed = tk.Radiobutton(text='Radio Button 1', variable=confirmed, 
                          value="yes", command=selected)
rconfirmed.pack()
rconfirmed= tk.Radiobutton(text='Radio Button 2', variable=confirmed, 
                          value="no", command=selected)
rconfirmed.pack()

root.mainloop()