2022年11月16日 星期三

Python GUI Clock 數位時鐘

 

from tkinter import *

from time import strftime

root = Tk()

root.geometry('500x350+300+300')

#root.iconbitmap('t1.ico')

root.title("源自於 ->C語言 中文網")

# 设置文本标签

lb = Label(root, font=("微軟雅黑", 50, "bold"), bg='#87CEEB', fg="#B452CD")

lb.pack(anchor="center", fill="both", expand=1)

# 定义一个mode标志

mode = 'time'

# 定义显示时间的函数

def showtime():

    if mode == 'time':

        #时间格式化处理   

        string = strftime("%H:%M:%S %p")

    else:

        string = strftime("%Y-%m-%d")

    lb.config(text=string)

    # 每隔 1秒钟执行time函数

    lb.after(1000, showtime)

# 定义鼠标处理事件,点击时间切换为日期样式显示

def mouseClick(event):

    global mode

    if mode == 'time':

        # 点击切换mode样式为日期样式

        mode = 'date'

    else:

        mode = 'time'

lb.bind("<Button>", mouseClick)

# 调用showtime()函数

showtime()

# 显示窗口

mainloop()



沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...