Close Menu
  • Home
  • Cd-player
  • Headphones
  • Microphones
  • Mp3-players
  • Receivers and Amplifiers
  • Speaker
Search
Facebook X (Twitter) Instagram
Facebook X (Twitter) Instagram
Dutchieeaudio
  • Home
  • Cd-player
  • Headphones
  • Microphones
  • Mp3-players
  • Receivers and Amplifiers
  • Speaker
Dutchieeaudio
Mp3-players

Python Project – Music Player. There are several Music Player… | by Himani Bansal | Wiki Flood | Oct, 2023

dutchieeaudio.comBy dutchieeaudio.com28 October 2023No Comments4 Mins Read

Himani Bansal
Wiki Flood

There are a number of Music Participant functions obtainable available in the market, and a few of them are already preinstalled in our machines. However at the moment we are going to make our personal Music participant utility in Python.

On this Python undertaking, we’re going to construct a Music Participant in Python utilizing its tkinter library, pygame library and os module. The tkinter library is used for making the Music Participant GUI;os module is used for the file path; mixer module from pygame library is used for loading and controlling the music.

  • To start, we are going to set up the mandatory libraries and modules in our system utilizing the pip installer.
  • This undertaking requires a stable understanding of Python, in addition to proficiency with the libraries and modules that might be utilized.

Importing the required libraries and modules in this system:

import os
from tkinter import *
from tkinter import filedialog
from pygame import mixer

os- This module helps in interacting with the working system.

tkinter- This library will assist us in making a GUI window for our app.

python Music Player Project

Initialising the GUI window:

root = Tk()
root.geometry("485x700+300+10")
root.title("PythonFlood-Music Participant")
root.config(bg='#0f0f0f')
root.resizable(False, False)
mixer.init()

root– It’s the identify of our GUI window.

Tk()– It initialises tkinter which suggests a GUI window is created.

geometry()– This methodology supplies the size and breadth to the GUI window.

resizeable()- This methodology permits the window to vary its measurement as per person want.

title()– This methodology provides title to the window

confg()– This methodology units the configuration of the window.

Creating Labels, Frames and Buttons-

We’ll create label, Body and Button widgets for the applying.

lbl = Label(root)
lbl.place(x=0, y=0)
root.after(0, replace, 0)

menu = PhotoImage(file='menu.png')
lb_menu = Label(root, picture=menu, width=485, top=120)
lb_menu.place(x=0, y=580)

frm_music = Body(root, bd=2, aid=RIDGE, width=485, top=100)
frm_music.place(x=0, y=580)

btn_play = PhotoImage(file='play1.png')
btn_p = Button(root, picture=btn_play, bg='#0f0f0f', top=60, width=60, command=playMusic)
btn_p.place(x=215, y=487)

btn_stop = PhotoImage(file='stop1.png')
btn_s = Button(root, picture=btn_stop, bg='#0f0f0f', top=60, width=60, command=mixer.music.cease)
btn_s.place(x=130, y=487)

btn_vol = PhotoImage(file='quantity.png')
btn_v = Button(root, picture=btn_vol, bg='#0f0f0f', top=60, width=60, command=mixer.music.unpause)
btn_v.place(x=20, y=487)

btn_pause = PhotoImage(file='pause1.png')

btn_ps = Button(root, picture=btn_pause, bg='#0f0f0f', top=60, width=60, command=mixer.music.pause)
btn_ps.place(x=300, y=487)

btn_browse = Button(root, textual content="Browse Music", font=('Arial,daring', 15), fg="Black", bg="#FFFFFF", width=45, command=addMusic)
btn_browse.place(x=0, y=550)

Label()– It’s used to show one line or a couple of line of textual content.

textual content– It’s used to show textual content on label.

font– It’s a model wherein font is written.

bg– It’s the background Color of the label.

place()- It’s used to set the place.

Body()- It is sort of a container, which is used for positioning the widgets.

Button()- It’s a button used to show on our window.

bd- It’s the border of the Button.

command- It’s used as a operate of a button when it’s clicked.

place()- It’s used to set the place.

Creating Scrollbar and Listbox-

We’ll create Scrollbar and listbox for viewing the chosen songs.

Scroll = Scrollbar(frm_music)
Playlist = Listbox(frm_music, width=100, font=('Arial,daring', 15), bg='#0f0f0f', fg='#00ff00', selectbackground="lightblue", cursor="hand2", bd=0, yscrollcommand=Scroll.set)
Scroll.config(command=Playlist.yview)
Scroll.pack(aspect=RIGHT, fill=Y)
Playlist.pack(aspect=RIGHT, fill=BOTH)

root.mainloop()

Listbox()- The Listbox widget is used to show the listing gadgets to the person. All textual content gadgets needs to be in the identical font and color.

aspect()- It will place the widget on Left, Proper, High and Backside.

yview()- It will make the scrollbar transfer vertically.

Scrollbar()- The Scrollbar Widget is used to slip down the content material of listbox.

yscrollcommand()- It should transfer the widget vertically.

root.mainloop()- It’s merely a way in the primary window that executes what we want to execute in an utility and ends the mainloop

Code for Shopping music-

We’ll create a operate for looking the music file.

def addMusic():
path = filedialog.askdirectory()
if path:
os.chdir(path)
songs = os.listdir(path)

for music in songs:
if music.endswith(".mp3"):
Playlist.insert(END, music)

  • addMusic operate opens a file dialog for choosing a listing containing music recordsdata.
  • The chosen listing is about as the present working listing.
  • Music recordsdata with the “.mp3” extension within the chosen listing are added to the Playlist.

Code for Enjoying music-

We’ll create a operate for enjoying the music.

def playMusic():
music_name = Playlist.get(ACTIVE)
print(music_name[0:-4])
mixer.music.load(Playlist.get(ACTIVE))
mixer.music.play()

lower_frm = Body(root, bg="#FFFFFF", width=485, top=180)
lower_frm.place(x=0, y=00)

frmcount = 30
frms = [PhotoImage(file='aa1.gif', format='gif -index %i' % i) for i in range(frmcount)]
def replace(ind):
body = frms[ind]
ind += 1
if ind == frmcount:
ind = 0
lbl.config(picture=body)
root.after(40, replace, ind)

  • playMusic operate performs the chosen music from the Playlist.
  • The chosen music file is loaded utilizing mixer.music.load() and performed utilizing mixer.music.play().
  • An animated body is created utilizing an inventory of PhotoImage objects (frames) representing every body of the animation.
  • The replace operate is named repeatedly to replace the animation frames.
  • The animated frames are displayed utilizing a Label (lbl).

Python Music Participant Output-

Music Player Output in python

On this Python undertaking, you’ve constructed a Music Participant utilizing Python with a user-friendly interface created utilizing the tkinter library. You’ll be able to simply add and play your music assortment by means of this utility, making it a useful instrument for managing and having fun with your music in your pc.

Source link

Previous ArticleJlab JBUDDIES STUDIO WIRELESS review
Next Article What we’re about to learn about House Speaker Mike Johnson
dutchieeaudio.com
  • Website

Related Posts

Mp3-players

Disney Mixes it Up with Pint-Sized MP3 Player

21 June 2024
Mp3-players

5 best MP3 players that are making a comeback, in UAE, for 2024

21 June 2024
Mp3-players

How to use an old iPod in 2024

12 June 2024
Add A Comment

Comments are closed.

Legal Pages
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Newsletter
  • 1721260058.97
  • xtw183877e04
  • 1721365373.41
  • xtw18387578d
  • 1721377124.95
  • xtw18387ac27
  • 1721459042.14
  • xtw183875992
  • 1721496721.65
  • xtw18387aff1
  • 1721550036.77
  • xtw183870926
  • 1721608772.46
  • xtw183872112
  • 1721642059.15
  • xtw18387ce5c
  • 1721722731.73
  • xtw18387a01c
  • 1721732666.61
  • xtw18387344c
  • 1721826265.77
  • xtw18387b73d
  • 1721845326.54
  • xtw18387c0ab
  • 1721919029.77
  • xtw183879928
  • 1721963272.34
  • xtw18387623a
  • 1722011094.34
  • xtw18387c60d
  • 1722083025.69
  • xtw183870438
  • 1722100133.88
  • xtw183879b14
  • 1722189810.87
  • xtw183879388
  • 1722200970.52
  • xtw18387e13f
  • 1722286548.66
  • xtw18387c911
  • 1722330244.57
  • xtw18387223b
  • 1722380823.25
  • xtw183876d45
  • 1722581742.45
  • xtw183871615
  • 1722954911.47
  • xtw18387aa3e
  • 1722980755.02
  • xtw18387c097
  • 1723109026.22
  • xtw183876bb4
  • 1723163087.89
  • xtw18387cf1b
  • 1723250845.2
  • xtw18387d9ca
  • 1723273213.76
  • xtw18387aa3e
  • 1723638833.62
  • xtw18387d01e
  • 1723903409.92
  • xtw183878a37
  • 1724042563.97
  • xtw18387c379
  • 1724319326.97
  • xtw1838754c5
  • 1724493323.11
  • xtw183875386
  • 1724818263.93
  • xtw18387734e
  • 1724830961.6
  • xtw183877516
  • 1725042692.45
  • xtw183879ace
  • 1725149770.06
  • xtw18387ca3a
  • 1725252354.37
  • xtw1838712d5
  • 1725678567.46
  • xtw18387421e
  • 1726039009.75
  • xtw18387d393
  • 1726238764.3
  • xtw1838794e1
  • 1726474254.94
  • xtw183873622
  • 1726640092.34
  • xtw18387e24b
  • 1726703235.82
  • xtw18387ef6e
  • 1726757882.84
  • xtw18387cf02
  • 1726873847.52
  • xtw1838797f1
  • 1726943818.71
  • xtw183877557
  • 1726988971.29
  • xtw18387001f
  • 1727102306.75
  • xtw183876e44
  • 1727178650.24
  • xtw18387692f
  • 1727217964.9
  • xtw183870f2a
  • 1727367160.35
  • xtw18387a1fe
  • 1727489615.44
  • xtw183874087
  • 1727524046.0
  • xtw18387013f
  • 1727633578.73
  • xtw18387b30b
  • 1727718636.19
  • xtw18387e053
  • 1727747856.84
  • xtw1838788bb
  • 1727863954.25
  • xtw183878141
  • 1727989549.99
  • xtw1838755b9
  • 1728053558.78
  • xtw183870782
  • 1728369151.96
  • xtw183874350
  • 1728500424.41
  • xtw183874b10
  • 1728552589.46
  • xtw18387ca03
  • 1728625224.51
  • xtw1838702bc
  • 1728751187.75
  • xtw18387757d
  • 1728870534.65
  • xtw18387925b
  • 1728879125.98
  • xtw183873526
  • 1728981920.73
  • xtw183870d8c
  • 1728984906.63
  • xtw18387ac1b
  • 1729006888.26
  • xtw183872102
  • 1729029837.74
  • xtw18387ac41
  • 1729076179.23
  • xtw1838730b5
  • 1729077915.32
  • xtw183872704
  • 1729107985.14
  • xtw18387dae3
  • 1729125669.99
  • xtw183874523
  • 1729161538.19
  • xtw18387b8f8
  • 1729163999.53
  • xtw18387bcd8
  • 1729192096.6
  • xtw18387f074
  • 1729221034.55
  • xtw1838779e3
  • 1729241667.13
  • xtw183875c3c
  • 1729241946.73
  • xtw1838775e7
  • 1729291868.92
  • xtw1838747b1
  • 1729319372.19
  • xtw183874081
  • 1729388868.33
  • xtw18387ae6c
  • 1729441505.34
  • xtw183879e57
  • 1729446349.31
  • xtw18387f348
  • 1729491175.42
  • xtw18387907c
  • 1729521595.82
  • xtw183873b01
  • 1729541278.96
  • xtw18387434d
  • 1729592350.13
  • xtw1838720d2
  • 1729598340.74
  • xtw18387b1fc
  • 1729643099.4
  • xtw183872268
  • 1729675867.44
  • xtw183874802
  • 1729692086.57
  • xtw1838760fb
  • 1729740406.13
  • xtw1838792b0
  • 1729751629.73
  • xtw18387c17e
  • 1729789431.04
  • xtw18387a1e5
  • 1729834050.02
  • xtw1838772fa
  • 1729844321.8
  • xtw183873453
  • 1729892934.59
  • xtw1838731a2
  • 1729912644.94
  • xtw18387cca5
  • 1729945688.04
  • xtw18387f10e
  • 1729987358.72
  • xtw18387cef2
  • xtw18387cef2
  • 1730000634.67
  • xtw18387db22
  • 1730049269.25
  • xtw183877696
  • 1730061953.84
  • xtw18387bf83
  • 1730098342.24
  • xtw1838712c3
  • 1730146293.34
  • xtw18387b0d2
  • 1730163229.75
  • xtw18387404d
  • 1730212279.08
  • xtw183879e23
  • 1730222269.84
  • xtw183874ee6
  • 1730262868.53
  • xtw183879664
  • 1730301901.67
  • xtw18387cd66
  • 1730314858.21
  • xtw183871c38
  • 1730365782.16
  • xtw18387d0e0
  • xtw18387d0e0
  • 1730382039.54
  • xtw18387c8df
  • 1730417848.46
  • xtw18387fb43
  • 1730463628.21
  • xtw183870bf1
  • 1730469942.5
  • xtw183870c22
  • 1730521550.77
  • xtw18387a72b
  • 1730545432.19
  • xtw18387570d
  • 1730574001.64
  • xtw18387daa6
  • 1730623133.08
  • xtw1838705d4
  • 1730623838.1
  • xtw18387ca3b
  • 1730674137.45
  • xtw183878545
  • 1730700578.31
  • xtw18387366f
  • 1730724715.7
  • xtw183876397
  • 1730774909.7
  • xtw18387402e
  • 1730776538.18
  • xtw183870c04
  • 1730824477.34
  • xtw183870279
  • 1730852564.75
  • xtw18387257d
  • 1730874153.36
  • xtw183876092
  • 1730924011.58
  • xtw1838727a7
  • 1730929738.14
  • xtw18387a413
  • 1730977413.06
  • xtw18387b414
  • 1731016072.48
  • xtw18387d868
  • 1731036386.97
  • xtw18387d94c
  • 1731097721.31
  • xtw1838761dc
  • 1731109040.81
  • xtw1838751bb
  • 1731160300.4
  • xtw183879b51
  • 1731202855.59
  • xtw183879680
  • 1731220833.34
  • xtw183876f74
  • 1731284010.92
  • xtw1838743d6
  • 1731294931.45
  • xtw18387c980
  • 1731348629.16
  • xtw183873961

Type above and press Enter to search. Press Esc to cancel.