(python)倒计时--UI版本

上代码:

import tkinter as tk
import time
import tkinter.messagebox
Hour = 1
Min = 1
Sce = 1
def sound():
    from winsound import Beep
    while True:
        Beep(880,250)

        Beep(988,250)

        Beep(523*2,600)

        Beep(988,300)

        Beep(523*2,600)

        Beep(659*2,600)

        Beep(988,1000)

        Beep(659,250)

        Beep(659,250)

        Beep(880,600)

        Beep(784,300)

        Beep(880,600)

        Beep(523*2,600)

        Beep(784,1000)
        
        Beep(659,600)

        Beep(698,800)

        Beep(659,300)

        Beep(698,600)

        Beep(523*2,600)

        Beep(659,980)

        Beep(523*2,250)

        Beep(523*2,250)

        Beep(523*2,250)

        Beep(988,600)

        Beep(739,300)

        Beep(739,600)

        Beep(988,600)

        Beep(988,1000)
        
        Beep(880,250)

        Beep(988,250)

        Beep(523*2,600)

        Beep(988,300)

        Beep(523*2,600)

        Beep(659*2,600)

        Beep(988,1000)

        Beep(659,250)

        Beep(659,250)

        Beep(880,600)

        Beep(784,300)

        Beep(880,600)

        Beep(523*2,600)

        Beep(784,1000)
        
        Beep(659,600)

        Beep(698,800)

        Beep(659,300)

        Beep(698,600)

        Beep(523*2,600)

        Beep(659,980)

        Beep(523*2,250)

        Beep(523*2,250)

        Beep(523*2,250)

        Beep(988,600)

        Beep(739,300)

        Beep(739,600)

        Beep(988,600)

        Beep(988,1000)
    #天空之城
    

def message():
    tkinter.messagebox.showinfo('关于','制作者:tc9625\nQQ:3536429078\n版本:倒计时v1.1')
def backgrounp(text): #背景
    x = -5
    F5 = tk.Label(bg = text)
    F5.place(relx=x,rely = 0,relwidth = 3,relheight = 3)
    while x < -0.1:
        x += 0.1 
        F5.place(relx=x,rely = 0,relwidth = 3,relheight = 3)
        win.update()

        if x == -0.1:
            break
win = tk.Tk()
win.title("倒计时")
win.geometry("1080x1920")
def mkmain(): # 构建生成主菜单的函数
    backgrounp("red")
    def AddHour():
        global Hour
        Hour += 1
        HourL = tk.Label(fg = "red",bg="blue",text = str(Hour)+" "*5+":",height=2)
        HourL.place(relx = 0.2,rely = 0.4)
        win.update()

    def KillHour():

        global Hour
        if Hour > 0:
            Hour -= 1
            HourL = tk.Label(fg = "red",bg="blue",text = str(Hour)+" "*5+":", height=2)
            HourL.place(relx = 0.2,rely = 0.4)
            win.update()

    def AddMin():
        global Min
        if Min == 59:
            AddHour()
            Min = 0
        else:
            Min += 1
        if len(str(Min)) == 1:
            MinL = tk.Label(fg = "red",bg="blue",text = str(Min)+" "*6+":", height=2)
        else:
            MinL = tk.Label(fg = "red",bg="blue",text = str(Min)+" "*5+":", height=2)
        MinL.place(relx = 0.25,rely = 0.4)
        win.update()
    def KillMin():
        global Min
        if Min == 0:
            Min = 59
            KillHour()
        else:
            Min -= 1
        if len(str(Min)) == 1:
            MinL = tk.Label(fg = "red",bg="blue",text = str(Min)+" "*6+":", height=2)
        else:
            MinL = tk.Label(fg = "red",bg="blue",text = str(Min)+" "*5+":", height=2)
        MinL.place(relx = 0.25,rely = 0.4)
        win.update()

    def killsc():

        global Sce
        
        if Sce == 0:
            Sce = 59
            KillMin()
        else:
            Sce -= 1
        if len(str(Sce)) == 1:

            SL = tk.Label(fg = "red",bg="blue",text = str(Sce)+" ", height=2)
        else:
            SL = tk.Label(fg = "red",bg="blue",text = str(Sce), height=2)
        SL.place(relx = 0.3,rely = 0.4)
        win.update()
    def addsc():
        global Sce
        
        if Sce == 59:
            AddMin()
            Sce = 0
        else:
            Sce += 1
        if len(str(Sce)) == 1:
            SL = tk.Label(fg = "red",bg="blue",text = str(Sce)+" ", height=2)
        else:
            SL = tk.Label(fg = "red",bg="blue",text = str(Sce), height=2)
        SL.place(relx = 0.3,rely = 0.4)
        win.update()

    def DaoJIShiCommand(): # 倒计时模块
        def begin():
            with open("./All.txt","r") as f:
                AllSce = int(f.read())
            backgrounp("green")
            HourL = tk.Label(fg = "red",bg="green",text = "还剩时间"+str(AllSce)+"秒",font = "Helvetica 16 bold italic")
            HourL.place(relheight = 1,relwidth = 1)
            from multiprocessing import Process,Pool
            def main():
                with open("./All.txt","r") as f:
                    AllSce = int(f.read())
                while True:
                    time.sleep(1)
                    AllSce -= 1
                    if AllSce == 0:
                        win.destroy()
                        print("时间到了,请关闭cmd以结束程序")
                        sound()
                    else:
                        HourL["text"] = "还剩时间"+str(AllSce)+"秒"
                        win.update()
                        print("111")
            main()


        def start():
            SceAll = Sce + Min * 60 + Hour *3600
            with open("./All.txt","w") as f:
                f.write(str(SceAll))
            begin()

        backgrounp("blue")
        HourL = tk.Label(fg = "red",bg="blue",text = str(Hour)+" "*5+":", height=2)
        HourL.place(relx = 0.2,rely = 0.4)

        AddHourL = tk.Button(text="+",command=AddHour)
        AddHourL.place(relx = 0.2,rely = 0.37)

        KillHourL = tk.Button(text="-",command=KillHour)
        KillHourL.place(relx = 0.2,rely = 0.44)
        
        MinL =  tk.Label(fg = "red",bg="blue",text = str(Min)+" "*5+":",height=2)
        MinL.place(relx = 0.25,rely = 0.4)

        AddMinL = tk.Button(text="+",command=AddMin)
        AddMinL.place(relx = 0.25,rely = 0.37)

        KillMinL = tk.Button(text="-",command=KillMin)
        KillMinL.place(relx = 0.25,rely = 0.44)

        SL =  tk.Label(fg = "red",bg="blue",text = str(Sce),height=2)
        SL.place(relx = 0.3,rely = 0.4)

        AddSL = tk.Button(text="+",command=addsc)
        AddSL.place(relx = 0.3,rely = 0.37)

        KillSL = tk.Button(text="-",command=killsc)
        KillSL.place(relx = 0.3,rely = 0.44)

        StartL = tk.Button(text="开始",command = start)
        StartL.place(relx = 0.4,rely= 0.3)

        Startl = tk.Button(text="输入时间并开始",command = start)
        Startl.place(relx = 0.4,rely= 0.5)
    def NaoZhongCommand():
        backgrounp("blue")

    DaoJiShi = tk.Button(text = "倒计时模式",command=DaoJIShiCommand)
    DaoJiShi.place(relx = 0.2,rely = 0.35,relwidth = 0.13,relheight = 0.13)

    NaoZhong = tk.Button(text = "闹钟模式",command=NaoZhongCommand)
    NaoZhong.place(relx = 0.7,rely = 0.35,relwidth = 0.13,relheight = 0.13)

    More = tk.Button(text="关于更多...",command=message)
    More.place(rely = 0.8,relx = 0.45)

mkmain()
win.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值