上代码:
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()