Python | Playing audio file in pygame
Python
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during 1985- 1990. Like Perl, Python source code is also available under the GNU General Public License (GPL). This tutorial gives enough understanding on Python programming language.
Why to Learn Python?
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.
Python is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Web Development Domain. I will list down some of the key advantages of learning Python
-Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP.
-Python is Interactive − You can actually sit at a Python prompt and interact with the interpreter directly to write your programs.
-Python is Object-Oriented − Python supports Object-Oriented style or technique of programming that encapsulates code within objects.
-Python is a Beginner's Language − Python is a great language for the beginner-level programmers and supports the development of a wide range of applications from simple text processing to WWW browsers to games.
pygame is a free and open-source cross-platform library for the development of multimedia applications like video games using Python. It uses the Simple DirectMedia Layer library and several other popular libraries to abstract the most common functions, making writing these programs a more intuitive task.
Installation
pip install pygame
If you are just getting started with pygame, you should be able to get started fairly quickly. Pygame comes with many tutorials and introductions. There is also full reference documentation for the entire library. Browse the documentation on the docs page.
The online documentation stays up to date with the development version of pygame on github. This may be a bit newer than the version of pygame you are using. To upgrade to the latest full release, run pip install pygame --upgrade in your terminal.
Best of all, the examples directory has many playable small programs which can get you started playing with the code right away.
Dependencies
Pygame is obviously strongly dependent on SDL and Python. It also links to and embeds several other smaller libraries. The font module relies on SDL_tff, which is dependent on freetype. The mixer (and mixer.music) modules depend on SDL_mixer. The image module depends on SDL_image, which also can use libjpeg and libpng. The transform module has an embedded version of SDL_rotozoom for its own rotozoom function. The surfarray module requires the Python NumPy package for its multidimensional numeric arrays. Dependency versions
Python >= 2.7 or PyPy >= 6.0.0 (and pypy3)
SDL >= 1.2.15
SDL_mixer >= 1.2.13
SDL_image >= 1.2.12
SDL_tff >= 2.0.11
SDL_gfx (optional, vendored in)
NumPy >= 1.6.2 (optional)
Example
from tkinter import *
import pygame
from tkinter import filedialog
root= Tk()
root.title('reanits.com')
root.iconbitmap('1.png')
root.geometry('300x400')
pygame.mixer.init()
songbox= Listbox(root, bg="black", fg="green",width=80,selectbackground="gray",selectforeground="black")
songbox.pack(pady=20)
backbtn= PhotoImage(file='image/forward101.png')
forwardbtn= PhotoImage(file='image/forward101.png')
playbtn= PhotoImage(file='image/Play101.png')
pausebtn= PhotoImage(file='image/pause101.png')
stopbtn= PhotoImage(file='image/Stop101.png')
controlframe= Frame(root)
controlframe.pack()
backbutton= Button(controlframe, image=backbtn, borderwidth=0)
frowardbutton= Button(controlframe, image=forwardbtn, borderwidth=0)
playbutton= Button(controlframe, image=playbtn, borderwidth=0)
pausebutton= Button(controlframe, image=pausebtn, borderwidth=0)
stopbutton= Button(controlframe, image=stopbtn, borderwidth=0)
backbutton.grid(row=0, column=1, padx=10)
frowardbutton.grid(row=0, column=2, padx=20)
playbutton.grid(row=0, column=3, padx=20)
pausebutton.grid(row=0, column=4, padx=20)
stopbutton.grid(row=0, column=5, padx=20)
root.mainloop
Please Watching My Video is Below
No comments:
Post a Comment