python實(shí)現(xiàn)敲木魚(yú)加功德包含加音效和敲擊動(dòng)作(附demo)
0、界面展示及視頻演示
這個(gè)是界面:

這個(gè)是地址:【用python做一個(gè)敲木魚(yú)試試-嗶哩嗶哩】 https://www.bilibili.com/video/BV1Vy4y1A7r5/
打包好的exe及源碼和其他文件在這里,聽(tīng)到有說(shuō)美化和尚和加倍功德,自己改和自己P吧 https://pan.baidu.com/s/1DCbo4hvN1KxGlSsr4EBqAw?pwd=gfqt
1、先做一個(gè)基本界面
import tkinter
from PIL import Image, ImageTk # pip install pillow
# 界面
top=tkinter.Tk()
top.title('敲木魚(yú)加功德')
top.geometry('410x400')
top.configure(bg='black')
# 準(zhǔn)備圖片
qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚(yú).jpg') # 轉(zhuǎn)化為tkinter可以使用的圖片
# 初始化功德
gongde=0
# 標(biāo)簽
label1=tkinter.Label(top,text='積攢功德:'+str(gongde),font=('華文新魏',15),fg='white',bg='black',width=18)
label1.place(x=100,y=70)
# 方法
def qiaomuyu():
# 設(shè)gongde為全局變量,并更新標(biāo)簽
global gongde
gongde=gongde+1
# 按鈕
button1=tkinter.Button(top,image=qiaomuyutupian,relief='ridge',command=qiaomuyu)
button1.place(x=100,y=100)
top.mainloop()2、用pygame添加聲音最簡(jiǎn)單,并用多線程啟動(dòng)(這樣不用等聲音播放完就可以繼續(xù)按了)
import tkinter
import threading
import pygame # pip install pygame
from PIL import Image, ImageTk # pip install pillow
# 準(zhǔn)備音頻
pygame.mixer.init()
pygame.mixer.music.load('敲.mp3')
# 界面
top=tkinter.Tk()
top.title('敲木魚(yú)加功德')
top.geometry('410x400')
top.configure(bg='black')
# 準(zhǔn)備圖片
qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚(yú).jpg') # 轉(zhuǎn)化為tkinter可以使用的圖片
# 初始化功德
gongde=0
# 標(biāo)簽
label1=tkinter.Label(top,text='積攢功德:'+str(gongde),font=('華文新魏',15),fg='white',bg='black',width=18)
label1.place(x=100,y=70)
# 方法
def qiaomuyu():
# 設(shè)gongde為全局變量,并更新標(biāo)簽
global gongde
gongde=gongde+1
label1.config(text='積攢功德:'+str(gongde))
# 多線程啟動(dòng)解決延時(shí),雖然延遲足夠小,但為了更有效果
th=threading.Thread(target=pygame.mixer.music.play)
th.start()
# 按鈕
button1=tkinter.Button(top,image=qiaomuyutupian,relief='ridge',command=qiaomuyu)
button1.place(x=100,y=100)
top.mainloop()3、添加上浮移動(dòng)的文字。
由于實(shí)在不能把控件設(shè)置成透明色,所以用個(gè)背景色為黑色的Text控件,只要逐行刪除就有效果了,同樣多線程啟動(dòng)
import time
import tkinter
import threading
import pygame # pip install pygame
from PIL import Image, ImageTk # pip install pillow
# 準(zhǔn)備音頻
pygame.mixer.init()
pygame.mixer.music.load('敲.mp3')
# 界面
top=tkinter.Tk()
top.title('敲木魚(yú)加功德')
top.geometry('410x400')
top.configure(bg='black')
# 準(zhǔn)備圖片
qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚(yú).jpg') # 轉(zhuǎn)化為tkinter可以使用的圖片
# 初始化功德
gongde=0
# 標(biāo)簽
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 qiaomuyu():
# 設(shè)gongde為全局變量,并更新標(biāo)簽
global gongde
gongde=gongde+1
label1.config(text='積攢功德:'+str(gongde))
# 多線程啟動(dòng)解決延時(shí),雖然延遲足夠小,但為了更有效果
th=threading.Thread(target=pygame.mixer.music.play)
th.start()
th2=threading.Thread(target=showplus)
th2.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()4、P一張敲到木魚(yú)的圖片,兩張圖片來(lái)回切換就有動(dòng)畫(huà)效果了,同樣多線程啟動(dòng)
import time
import tkinter
import threading
import pygame # pip install pygame
from PIL import Image, ImageTk # pip install pillow
# 準(zhǔn)備音頻
pygame.mixer.init()
pygame.mixer.music.load('敲.mp3')
# 界面
top=tkinter.Tk()
top.title('敲木魚(yú)加功德')
top.geometry('410x400')
top.configure(bg='black')
# 準(zhǔn)備圖片
qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚(yú).jpg') # 轉(zhuǎn)化為tkinter可以使用的圖片
qiaomuyutupian2=ImageTk.PhotoImage(file='敲木魚(yú)2.jpg') # 轉(zhuǎn)化為tkinter可以使用的圖片
# 初始化功德
gongde=0
# 標(biāo)簽
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():
# 設(shè)gongde為全局變量,并更新標(biāo)簽
global gongde
gongde=gongde+1
label1.config(text='積攢功德:'+str(gongde))
# 多線程啟動(dòng)解決延時(shí),雖然延遲足夠小,但為了更有效果
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()到此這篇關(guān)于python實(shí)現(xiàn)敲木魚(yú)加功德包含加音效和敲擊動(dòng)作(附demo)的文章就介紹到這了,更多相關(guān)python 敲木魚(yú)加功德內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Keras之自定義損失(loss)函數(shù)用法說(shuō)明
這篇文章主要介紹了Keras之自定義損失(loss)函數(shù)用法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06
Python for循環(huán)與range函數(shù)的使用詳解
這篇文章主要介紹了Python for循環(huán)與range函數(shù)的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
Python項(xiàng)目打包并部署到Docker詳細(xì)步驟
這篇文章主要介紹了如何使用Docker將Python項(xiàng)目打包成鏡像并部署為容器,包括準(zhǔn)備工作、Python項(xiàng)目結(jié)構(gòu)、編寫(xiě)Dockerfile、構(gòu)建Docker鏡像、運(yùn)行容器、優(yōu)化鏡像大小、自動(dòng)化部署以及總結(jié),需要的朋友可以參考下2025-03-03
python簡(jiǎn)單實(shí)現(xiàn)獲取當(dāng)前時(shí)間
最近項(xiàng)目中經(jīng)常需要python去取當(dāng)前的時(shí)間,雖然不是很難,但是老是忘記,用一次丟一次,為了能夠更好的記住,我今天特意寫(xiě)下python 當(dāng)前時(shí)間這篇文章,如果你覺(jué)的對(duì)你有用的話,可以收藏下。2016-08-08
將python代碼打包成.exe文件直接運(yùn)行的具體步驟
小編最近收到了一個(gè)小伙伴的問(wèn)題,就是那么多有趣的代碼,怎么發(fā)給別人,讓沒(méi)有python環(huán)境的小伙伴也可以使用呢,本文小編將帶著大家探索如何將自己的python代碼打包成.exe可執(zhí)行文件,一起來(lái)看看吧2024-02-02

