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()







沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa 開源碼網頁式圖控平台

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...