您好,登錄后才能下訂單哦!
#encoding=utf-8
import tkinter as tk
window = tk.Tk()
window.title("測試單選框")
window.geometry("400x200")
var = tk.StringVar()
label_1 = tk.Label(window,bg="yellow",textvar=var,width=10,height=1,text="label_1")
label_1.pack()
def print_selection():
#label的config函數可以改變label對象里定義的參數的值
label_1.config(text= "你選擇了選項: " + var.get())
label_1.config(bg="green")
label_1.config(width=12)
#定義單選按鈕,var=var,value="A" 指把value的值賦值給var
radiobutton_1 = tk.Radiobutton(window,text="選項A",var=var,value="A",command=print_selection)
radiobutton_1.pack()
radiobutton_2 = tk.Radiobutton(window,text="選項B",var=var,value="B",command=print_selection)
radiobutton_2.pack()
radiobutton_3 = tk.Radiobutton(window,text="選項C",var=var,value="C",command=print_selection)
radiobutton_3.pack()
window.mainloop()
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。