2022年11月16日 星期三

Python GUI 標籤 Label ---- EX2.23

 # ch2_23.py

from tkinter import *


counter = 0                                 # 計數的全域變數

def run_counter(digit):                     # 數字變數內容的更動

    def counting():                         # 更動數字方法

        global counter

        counter += 1                        # 定義這是全域變數

        digit.config(text=str(counter))     # 列出標籤數字內容

        digit.after(1000,counting)          # 隔一秒後呼叫counting

    counting()                              # 啟動呼叫


root = Tk()

root.title("ch2_23")

digit=Label(root,bg="yellow",fg="blue",     # 黃底藍字

            height=3,width=10,              # 寬10高3

            font="Helvetic 20 bold")        # 字型設定

digit.pack()

run_counter(digit)                          # 呼叫數字更動方法


root.mainloop()







沒有留言:

張貼留言

Telegram +ESP32自動發報機

  Telegram   +ESP32自動發報機 這套系統是一個典型的 IoT(物聯網)架構 ,結合了遠端配置(Python)、通訊中介(MQTT)與硬體執行(ESP32)。 以下我為您拆解這兩支程式的核心運作原理: 一、 系統架構流程 Python 端 (控制台) :使用者輸入...