1. 程式人生 > >tkinter 04 Radiobutton 選擇按鈕

tkinter 04 Radiobutton 選擇按鈕

sina pack print cti HR imp mman IT you

  • 運行結果:http://ww1.sinaimg.cn/large/de060ec1ly1fqedlvhm4ag20fe09eaaf.gif
  • # coding=gbk
    # 註意:選中按鈕時執行下面的命令,config意為配置
    #       lable.config(text = "you have selected " + var.get())
    # 運行結果:http://ww1.sinaimg.cn/large/de060ec1ly1fqedlvhm4ag20fe09eaaf.gif
    import tkinter
    window = tkinter.Tk()
    window.title("jkn1234")
    window.geometry(
    "500x500") var = tkinter.StringVar() lable = tkinter.Label( window, bg = yellow, height = 6, text = empty ) def print_selection(): lable.config(text = "you have selected " + var.get()) lable.pack() radiobutton1 = tkinter.Radiobutton( window, variable = var, value = A,#
    點擊按鈕時將按鈕var的值設置為‘A’ text = "option A", command = print_selection ) radiobutton1.pack() radiobutton2 = tkinter.Radiobutton( window, variable = var, value = B,#點擊按鈕時將按鈕var的值設置為‘B’ text = "option B", command = print_selection ) radiobutton2.pack() window.mainloop()

tkinter 04 Radiobutton 選擇按鈕