Python 入門指南 5.0
exercise2909.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 | # 從 exercise2908 引入 get_result
from exercise2908 import get_result
# 從標準程式庫中引入 Tk 的所有內容
from tkinter import *
# 引入 time
import time
# 執行部分
if __name__ == '__main__':
# 文字逐行顯示動畫
def update_text():
global current_line
global text_lines
global show_text
if current_line < len(text_lines):
show_text += text_lines[current_line]
text_label.config(text=show_text)
current_line += 1
root.after(900, update_text)
# 建立 Tk 視窗
root = Tk()
# 設定視窗標題
root.title("單人擲骰子模擬")
# 顯示的文字資料
text_lines = get_result()
# 記錄行數
current_line = 0
# 暫存顯示資料
show_text = ""
# 加入視窗元件文字標籤
text_label = Label(root, text="",
width="40", height="9",
bg="black", fg="white",
font=("SF Pro", 48))
# 使用包裹版面管理員
text_label.pack()
# 呼叫文字動畫函數
update_text()
# 呼叫維持視窗運作的 mainloop()
root.mainloop()
# 檔名: exercise2909.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 11 月
|