倒计时小程序桌面显示_python实例小程序——倒计时

from tkinter import *

import time

import tkinter.messagebox

class App:

def __init__(self,master):

frame = Frame(master)

frame.pack()

self.entryWidget = Entry(frame)

self.entryWidget["width"] = 15

self.entryWidget.pack(side=LEFT)

self.hi_there = Button(frame, text="开始", command=self.start)

self.hi_there.pack(side=LEFT)

self.button = Button(frame, text="退出", fg="red", command=frame.quit)

self.button.pack(side=LEFT)

def start(self):

text = self.entryWidget.get().strip()

if text != "":

num = int(text)

self.countDown(num)

def countDown(self,seconds):

lbl1.config(bg='yellow')

lbl1.config(height=3, font=('times', 20, 'bold'))

for k in range(seconds, 0, -1):

if k == 30:

print("a")

if k== 29:

print("a")

if k== 28:

print("a")

lbl1["text"] = k

root.update()

time.sleep(1)

lbl1.config(bg='red')

lbl1.config(fg='white')

lbl1["text"] = "时间到!"

tkMessageBox.showinfo("时间到!","时间到!")

def GetSource():

get_window = Tkinter.Toplevel(root)

get_window.title('Source File?')

Tkinter.Entry(get_window, width=30,

textvariable=source).pack()

Tkinter.Button(get_window, text="Change",

command=lambda: update_specs()).pack()

root = Tk()

root.title("Countdown")

lbl1 = Label()

lbl1.pack(fill=BOTH, expand=1)

app = App(root)

root.mainloop()

1773f489405ebc2617eab54fe627498f.png
472e7a219b5cf0e77cda9ca540cc0470.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值