Python 入門指南 5.0

exercise3308.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
# 從標準程式庫引入 Tk
from tkinter import *
# 從 tkinter 引入 ttk
from tkinter import ttk

# 練習用的視窗類別
class Application(ttk.Frame):
    def __init__(self, master):
        ttk.Frame.__init__(self, master)
        self.winfo_toplevel().title("練習的視窗")
        self.grid()
        self.createWidgets()
        self.style = ttk.Style()
        self.style.theme_use("alt")
        for child in self.winfo_children():
            child.grid_configure(padx=5, pady=3)

    def createWidgets(self):
        self.progress = ttk.Progressbar(self)
        self.progress["orient"] = "horizontal"
        self.progress["length"] = 300
        self.progress["mode"] = "determinate"
        self.progress["maximum"] = 100
        self.progress.grid(row=0, column=0, sticky=N)

        self.scale = Scale(self)
        self.scale["orient"] = "horizontal"
        self.scale["length"] = 300
        self.scale["width"] = 30
        self.scale["command"] = self.do_something
        self.scale.grid(row=1, column=0, sticky=N)

    def do_something(self, event=None):
        self.progress["value"] = self.scale.get()

# 執行部分
if __name__ == '__main__':
    # 建立 Tk 應用物件
    root = Tk()
    # 建立視窗物件
    app = Application(master=root)
    # 呼叫維持視窗運作的 mainloop()
    root.mainloop()

# 檔名: exercise3308.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 11 月

回到練習題目
上一頁 exercise3307.py
回 Python 入門指南 5.0 首頁
下一頁 exercise3309.py
回 Python 教材首頁
回程式語言教材首頁