python倒计时器弹出计时窗口,python开发的简单窗口界面的倒计时界面

下面的代码通过Tkinter制作windows窗口界面,然后时间了一个简单的倒计时功能,代码可以直接运行

# Countdown using Tkinter

from Tkinter import *

import time

import tkMessageBox

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="Start", command=self.start)

self.hi_there.pack(side=LEFT)

self.button = Button(frame, text="QUIT", 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):

lbl1["text"] = k

root.update()

time.sleep(1)

lbl1.config(bg='red')

lbl1.config(fg='white')

lbl1["text"] = "Time up!"

tkMessageBox.showinfo("Time up!","Time up!")

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

开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明python开发的简单窗口界面的倒计时界面!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值