python實現(xiàn)敲木魚加功德包含加音效和敲擊動作(附demo)
0、界面展示及視頻演示
這個是界面:
這個是地址:【用python做一個敲木魚試試-嗶哩嗶哩】 https://www.bilibili.com/video/BV1Vy4y1A7r5/
打包好的exe及源碼和其他文件在這里,聽到有說美化和尚和加倍功德,自己改和自己P吧 https://pan.baidu.com/s/1DCbo4hvN1KxGlSsr4EBqAw?pwd=gfqt
1、先做一個基本界面
import tkinter from PIL import Image, ImageTk # pip install pillow # 界面 top=tkinter.Tk() top.title('敲木魚加功德') top.geometry('410x400') top.configure(bg='black') # 準備圖片 qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚.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 qiaomuyu(): # 設gongde為全局變量,并更新標簽 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添加聲音最簡單,并用多線程啟動(這樣不用等聲音播放完就可以繼續(xù)按了)
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') # 準備圖片 qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚.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 qiaomuyu(): # 設gongde為全局變量,并更新標簽 global gongde gongde=gongde+1 label1.config(text='積攢功德:'+str(gongde)) # 多線程啟動解決延時,雖然延遲足夠小,但為了更有效果 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、添加上浮移動的文字。
由于實在不能把控件設置成透明色,所以用個背景色為黑色的Text控件,只要逐行刪除就有效果了,同樣多線程啟動
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') # 準備圖片 qiaomuyutupian=ImageTk.PhotoImage(file='敲木魚.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 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() # 按鈕 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一張敲到木魚的圖片,兩張圖片來回切換就有動畫效果了,同樣多線程啟動
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') # 準備圖片 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實現(xiàn)敲木魚加功德包含加音效和敲擊動作(附demo)的文章就介紹到這了,更多相關python 敲木魚加功德內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python 使用 docopt 解析json參數(shù)文件過程講解
這篇文章主要介紹了Python 使用 docopt 解析json參數(shù)文件過程講解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-08-08python 調(diào)用win32pai 操作cmd的方法
下面小編就為大家?guī)硪黄猵ython 調(diào)用win32pai 操作cmd的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05Python cookbook(數(shù)據(jù)結構與算法)將多個映射合并為單個映射的方法
這篇文章主要介紹了Python cookbook(數(shù)據(jù)結構與算法)將多個映射合并為單個映射的方法,結合實例形式分析了Python字典映射合并操作相關實現(xiàn)技巧,需要的朋友可以參考下2018-04-04python輸入整條數(shù)據(jù)分割存入數(shù)組的方法
今天小編就為大家分享一篇python輸入整條數(shù)據(jù)分割存入數(shù)組的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11