wxPython实现整点报时
作者:吴越南蛮 时间:2023-06-11 05:25:39
本文实例为大家分享了wxPython整点报时的具体代码,供大家参考,具体内容如下
# C盘要有个wav文件,内含报时音频
import wx
import time# 获取时间
import wave# 波形处理
import pyaudio# 播放器
class MyFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,title="整点报时",size=(410,150),style=wx.SYSTEM_MENU|wx.MINIMIZE_BOX|wx.CLOSE_BOX|wx.CAPTION)
self.Center()
self.InitUI()
def InitUI(self):
panel = wx.Panel(self)
panel.SetBackgroundColour("green")
t = time.strftime("%H:%M:%S",time.localtime())# 设置初始值
self.text = wx.StaticText(panel,-1,t)
font = wx.Font(72,wx.DEFAULT,wx.FONTSTYLE_NORMAL,wx.NORMAL,faceName="黑体")
self.text.SetFont(font)
self.text.SetForegroundColour("red")
self.timer = wx.Timer(self)# 创建一个计时器对象
self.Bind(wx.EVT_TIMER,self.Time,self.timer)# 绑定计时器事件
self.timer.Start(1000)# 计时器计时1秒
def Time(self,event):
t = time.strftime("%H:%M:%S",time.localtime())
self.text.SetLabel(t)# 刷新显示
for i in range(0,24):
temp = "{:0>2d}:00:00".format(i)
if t == temp:# 判断是否为整点
filename = "C:\\wav\\"+"{:0>2d}.wav".format(i)# 找到对应的wav文件路径
self.Sound(filename)# 播放声音
break
def Sound(self,filename):
f = wave.open(filename,'rb')# 加载音频文件(wav)
pms = f.getparams()# 获取音频的属性参数
nchannels, sampwidth, framerate, nframes = pms[:4]# 单独提取出各参数的值,并加以定义
p = pyaudio.PyAudio()# 创建一个播放器
s = p.open(format = p.get_format_from_width(sampwidth),channels = nchannels,rate = framerate,output = True)# 将音频转换为音频流
while True:
data = f.readframes(1024)# 按照1024大小的块,读取音频数据,得到一系列二进制编码
if data == b'':
break
s.write(data)# 开始按照音频的参数,播放音频
s.close()
p.terminate()
if __name__ == '__main__':
app = wx.App() # 初始化wx.App类
frame = MyFrame(parent=None, id=-1) # 实例MyFrame类,并传递参数
frame.Show() # 显示窗口
app.MainLoop() # 调用App类的MainLoop()主循环方法
来源:https://blog.csdn.net/weixin_43069875/article/details/103098529
标签:wxPython,整点报时
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
jQuery 1.4新特性及其变化(上)
2010-01-18 16:33:00
Vue实现模糊查询的简单方法实例
2024-04-28 09:20:55
![](https://img.aspxhome.com/file/2023/1/133111_0s.png)
Vue使用JSEncrypt实现rsa加密及挂载方法
2024-06-05 10:02:30
在ASP.NET 2.0中操作数据之四十六:使用SqlDataSource控件检索数据
2023-07-04 14:31:37
![](https://img.aspxhome.com/file/2023/6/76346_0s.gif)
python实现ping命令小程序
2022-12-14 02:16:26
![](https://img.aspxhome.com/file/2023/9/75159_0s.png)
自适应浏览器位置的div效果
2008-05-29 13:15:00
![](https://img.aspxhome.com/file/UploadPic/20085/29/div_24s.jpg)
Oracle中的分析函数汇总
2024-01-20 05:59:38
![](https://img.aspxhome.com/file/2023/1/67031_0s.jpg)
如何用METADATA替换ADOVBS.INC?
2010-06-12 12:54:00
Go语言基础switch条件语句基本用法及示例详解
2024-04-26 17:33:30
![](https://img.aspxhome.com/file/2023/9/133979_0s.png)
Python中关于文件的具体操作与介绍
2022-03-25 20:27:24
![](https://img.aspxhome.com/file/2023/0/112150_0s.png)
Python接口自动化 之用例读取方法总结
2023-12-14 06:47:22
![](https://img.aspxhome.com/file/2023/3/90353_0s.png)
Python读csv文件去掉一列后再写入新的文件实例
2022-05-13 14:04:12
前端开发中一些常用技巧总结
2010-07-18 13:13:00
腾讯网QQ首页诞生的艰辛历程
2008-11-06 11:05:00
![](https://img.aspxhome.com/file/UploadPic/200811/6/01-77s.jpg)
vue-router懒加载速度缓慢问题及解决方法
2024-04-27 16:07:23
![](https://img.aspxhome.com/file/2023/5/133005_0s.png)
使用 Vue cli 3.0 构建自定义组件库的方法
2024-05-05 09:07:50
pycharm中使用request和Pytest进行接口测试的方法
2022-06-30 03:34:46
![](https://img.aspxhome.com/file/2023/9/90599_0s.png)
python中利用numpy.array()实现俩个数值列表的对应相加方法
2022-08-26 01:49:25
用Python写王者荣耀刷金币脚本
2022-03-04 11:55:28
关于阿里云oss获取sts凭证 app直传 python的实例
2021-04-29 14:16:11