python實(shí)現(xiàn)敲木魚加功德包含加音效和敲擊動(dòng)作(附demo)
0、界面展示及視頻演示
這個(gè)是界面:
這個(gè)是地址:【用python做一個(gè)敲木魚試試-嗶哩嗶哩】 https://www.bilibili.com/video/BV1Vy4y1A7r5/
打包好的exe及源碼和其他文件在這里,聽到有說(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('敲木魚加功德') top.geometry('410x400') top.configure(bg='black') # 準(zhǔn)備圖片 qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚.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('敲木魚加功德') top.geometry('410x400') top.configure(bg='black') # 準(zhǔn)備圖片 qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚.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('敲木魚加功德') top.geometry('410x400') top.configure(bg='black') # 準(zhǔn)備圖片 qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚.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一張敲到木魚的圖片,兩張圖片來(lái)回切換就有動(dòng)畫效果了,同樣多線程啟動(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('敲木魚加功德') top.geometry('410x400') top.configure(bg='black') # 準(zhǔn)備圖片 qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚.jpg') # 轉(zhuǎn)化為tkinter可以使用的圖片 qiaomuyutupian2=ImageTk.PhotoImage(file='敲木魚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)敲木魚加功德包含加音效和敲擊動(dòng)作(附demo)的文章就介紹到這了,更多相關(guān)python 敲木魚加功德內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python 使用 docopt 解析json參數(shù)文件過程講解
這篇文章主要介紹了Python 使用 docopt 解析json參數(shù)文件過程講解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08python 調(diào)用win32pai 操作cmd的方法
下面小編就為大家?guī)?lái)一篇python 調(diào)用win32pai 操作cmd的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-05-05Python cookbook(數(shù)據(jù)結(jié)構(gòu)與算法)將多個(gè)映射合并為單個(gè)映射的方法
這篇文章主要介紹了Python cookbook(數(shù)據(jù)結(jié)構(gòu)與算法)將多個(gè)映射合并為單個(gè)映射的方法,結(jié)合實(shí)例形式分析了Python字典映射合并操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-04-04matlab 計(jì)算灰度圖像的一階矩,二階矩,三階矩實(shí)例
這篇文章主要介紹了matlab 計(jì)算灰度圖像的一階矩,二階矩,三階矩實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-04-04python輸入整條數(shù)據(jù)分割存入數(shù)組的方法
今天小編就為大家分享一篇python輸入整條數(shù)據(jù)分割存入數(shù)組的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2018-11-11Python之freegames?零代碼的22個(gè)小游戲集合
這篇文章主要介紹了,Python之freegames?零代碼的22個(gè)小游戲集合,文章內(nèi)容詳細(xì),簡(jiǎn)單易懂,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2023-01-01