Python 入門指南 5.0
exercise3106.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # 從標準程式庫引入 Tk from tkinter import * # 練習用的視窗類別 class Application(Frame): def __init__(self, master): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.value = StringVar() self.radiobutton1 = Radiobutton(self) self.radiobutton1["text"] = "選我1" self.radiobutton1["value"] = "選我1" self.radiobutton1["variable"] = self.value self.radiobutton1.grid(row=0, column=0) self.radiobutton1.select() self.radiobutton2 = Radiobutton(self) self.radiobutton2["text"] = "選我2" self.radiobutton2["value"] = "選我2" self.radiobutton2["variable"] = self.value self.radiobutton2.grid(row=1, column=0) self.radiobutton3 = Radiobutton(self) self.radiobutton3["text"] = "選我3" self.radiobutton3["value"] = "選我3" self.radiobutton3["variable"] = self.value self.radiobutton3.grid(row=2, column=0) self.radiobutton4 = Radiobutton(self) self.radiobutton4["text"] = "選我4" self.radiobutton4["value"] = "選我4" self.radiobutton4["variable"] = self.value self.radiobutton4.grid(row=3, column=0) self.label = Label(self) self.label["text"] = "" self.label.grid(row=4, column=0) # 執行部分 if __name__ == '__main__': # 建立 Tk 應用物件 root = Tk() # 建立視窗物件 app = Application(master=root) # 呼叫維持視窗運作的 mainloop() root.mainloop() # 檔名: exercise3106.py # 說明:《Python入門指南》的練習 # 網站: http://kaiching.org # 作者: 張凱慶 # 時間: 2023 年 11 月 |