基于Python实现敲电子木鱼效果
作者:hvinsion
这篇文章主要为大家详细介绍了如何基于Python实现敲电子木鱼加功德效果,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起了解一下
1. 简介
用Python 敲电子木鱼,使用自动功德机,见机甲佛祖,修赛博真经。无需登录即可每日敲木鱼,每敲一下功德+1,心中的焦虑似乎也减少了呢。
功能:
1、禅意随行,一键敲心!电子木鱼,随时随地,修行不断。
2、通过鼠标点击木鱼图片来积攒功德。
3. 加敲击音效和敲击动作。
2. 运行效果

3. 相关源码
import time
import tkinter
import threading
import pygame # pip install pygame
from PIL import Image, ImageTk # pip install pillow
# 准备音频
pygame.mixer.init()
pygame.mixer.music.load('敲.mp3')
# 界面
top=tkinter.Tk()
top.title('敲电子木鱼,攒无量功德')
top.geometry('410x400')
top.configure(bg='black')
top.iconbitmap('muyu.ico')
# 准备图片
qiaomuyutupian=ImageTk.PhotoImage(file='敲木鱼.jpg') # 转化为tkinter可以使用的图片
qiaomuyutupian2=ImageTk.PhotoImage(file='敲木鱼2.jpg') # 转化为tkinter可以使用的图片
# 初始化功德
gongde=0
# 标签
label1=tkinter.Label(top,text='积攒功德:'+str(gongde),font=('华文新魏',15),fg='white',bg='black',width=18)
label1.place(x=100,y=70)
def showplus():
for i in range(4):
text1.insert('insert',' \n')
else:
text1.insert('insert',' 功德 + 1')
for i in range(5):
time.sleep(0.03)
text1.delete(1.0, 2.0)
def changetupian():
button1.config(image=qiaomuyutupian2)
time.sleep(0.1)
button1.config(image=qiaomuyutupian)
# 方法
def qiaomuyu():
# 设gongde为全局变量,并更新标签
global gongde
gongde=gongde+1
label1.config(text='积攒功德:'+str(gongde))
# 多线程启动解决延时,虽然延迟足够小,但为了更有效果
th=threading.Thread(target=pygame.mixer.music.play)
th.start()
th2=threading.Thread(target=showplus)
th2.start()
th3=threading.Thread(target=changetupian)
th3.start()
# 按钮
button1=tkinter.Button(top,image=qiaomuyutupian,relief='ridge',command=qiaomuyu)
button1.place(x=100,y=100)
text1=tkinter.Text(top,width=10,height=5,bg='black',bd=0,foreground='white')
text1.place(x=125,y=115)
top.mainloop()
到此这篇关于基于Python实现敲电子木鱼效果的文章就介绍到这了,更多相关Python敲电子木鱼内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
