加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python实现的简单窗口倒计时界面实例

发布时间:2020-12-16 21:03:48 所属栏目:Python 来源:网络整理
导读:本篇章节讲解python实现的简单窗口倒计时界面。供大家参考研究。具体分析如下: 下面的代码通过Tkinter制作windows窗口界面,然后时间了一个简单的倒计时功能,代码可以直接运行 # Countdown using Tkinter from Tkinter import *import timeimport

本篇章节讲解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,-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程序设计有所帮助。

您可能感兴趣的文章:

  • python在windows下创建隐藏窗口子进程的方法
  • Python实现遍历windows所有窗口并输出窗口标题的方法
  • python实现根据窗口标题调用窗口的方法
  • python中pygame针对游戏窗口的显示方法实例分析(附源码)
  • wxPython窗口的继承机制实例分析
  • python3+PyQt5使用数据库窗口视图
  • wxPython实现窗口用图片做背景
  • Python使用Windows API创建窗口示例【基于win32gui模块】

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读