当前位置: 首页 > news >正文

python实现一个简单的桌面倒计时小程序

本章内容主要是利用python制作一个简单的桌面倒计时程序,包含开始、重置 、设置功能。

目录

一、效果演示

二、程序代码


一、效果演示

二、程序代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author: Roc-xb
"""import tkinter as tk
from tkinter import simpledialog
from tkinter import messageboxclass CountdownTimer:def __init__(self, root):self.root = rootself.root.title("倒计时程序")self.root.geometry("450x300")self.countdown_value = 60self.is_counting = Falseself.canvas = tk.Canvas(self.root, width=200, height=200, bg="white")self.canvas.place(x=20, y=20)self.countdown_label = tk.Label(self.root, text="倒计时: 60s", font=("Arial", 20))self.countdown_label.place(x=250, y=20)self.start_button = tk.Button(self.root, text="开始", command=self.start_countdown)self.start_button.place(x=250, y=70)self.reset_button = tk.Button(self.root, text="重置", command=self.reset_countdown)self.reset_button.place(x=250, y=120)self.set_button = tk.Button(self.root, text="设置", command=self.set_countdown)self.set_button.place(x=250, y=170)def start_countdown(self):if self.is_counting:returnself.is_counting = Trueself.countdown()def countdown(self):if self.countdown_value > 0 and self.is_counting is True:self.countdown_value -= 1self.countdown_label.config(text="倒计时: " + str(self.countdown_value) + "s")self.canvas.delete("all")self.canvas.create_rectangle(0, 200 - self.countdown_value * 2, 200, 300, fill="green")self.root.after(1000, self.countdown)elif self.countdown_value > 0 and self.is_counting is False:self.canvas.delete("all")self.is_counting = Falsereturnelse:self.is_counting = Falsemessagebox.showinfo("提示", "倒计时结束")def reset_countdown(self):self.is_counting = Falseself.countdown_value = 60self.countdown_label.config(text="倒计时: " + str(self.countdown_value) + "s")self.canvas.delete("all")def set_countdown(self):if self.is_counting:returnvalue = tk.simpledialog.askinteger("设置倒计时", "请输入倒计时时间(秒):", parent=self.root)if value is not None:self.countdown_value = valueself.countdown_label.config(text="倒计时: " + str(self.countdown_value) + "s")self.canvas.delete("all")if __name__ == '__main__':root = tk.Tk()app = CountdownTimer(root)root.mainloop()

http://www.lryc.cn/news/231525.html

相关文章:

  • 解决STM32F429烧录程序后还需复位才能植入程序的bug
  • 使用Golang调用摄像头
  • 【Linux网络】1分钟使用shell脚本完成DNS主从解析服务器部署(适用于centos主机)
  • 基于SSM的校园停车场管理系统设计与实现
  • 块设备 I/O 请求送达到外部设备
  • 【ArcGIS Pro二次开发】(76):面积平差工具
  • 4、智能家居框架设计和代码文件工程建立
  • 网络编程TCP/UDP
  • 移远EC600U-CN开发板 11.15
  • Docker - MySQL Database is uninitialized and password option is not specified
  • Elasticsearch 之聚合分析
  • Django(七、模型层)
  • LeetCode105. Construct Binary Tree from Preorder and Inorder Traversal
  • python链表_递归求和_递归求最大小值
  • Java中生成指定字体的印章
  • Winodws核心编程 多线程
  • 旺店通·企业版对接打通金蝶云星空查询调拨单接口与分布式调入单新增接口
  • 关于对Java中volatile关键字的理解与简述
  • 37 _ 贪心算法:如何用贪心算法实现Huffman压缩编码?
  • Unity中Shader矩阵的逆矩阵
  • 我给网站做公安备案年度安全评估
  • iceoryx(冰羚)-通信中间件解析
  • Windows系统CMake+VS编译protobuf
  • HarmonyOS开发(三):ArkTS基础
  • Java排序算法之堆排序
  • 『GitHub项目圈选02』一款可实现视频自动翻译配音为其他语言的开源项目
  • Unity - Cinemachine
  • 准备搞OpenStack了,先装一台最新的Ubuntu 23.10
  • Android 12 客制化修改初探-Launcher/Settings/Bootanimation
  • 【JavaEE初阶】 HTML基础详解