|
| 1 | +# import libraries |
| 2 | +import os |
| 3 | +from tkinter import * |
| 4 | +from tkinter import filedialog |
| 5 | +from pygame import mixer |
| 6 | + |
| 7 | +# Create a GUI window |
| 8 | +root = Tk() |
| 9 | +root.title("Music Player") |
| 10 | +root.geometry("920x600+290+85") |
| 11 | +root.configure(background='#0f1a2b') |
| 12 | +root.resizable(False, False) |
| 13 | + |
| 14 | +mixer.init() |
| 15 | + |
| 16 | +# Create a function to open a file |
| 17 | + |
| 18 | + |
| 19 | +def AddMusic(): |
| 20 | + path = filedialog.askdirectory() |
| 21 | + if path: |
| 22 | + os.chdir(path) |
| 23 | + songs = os.listdir(path) |
| 24 | + |
| 25 | + for song in songs: |
| 26 | + if song.endswith(".mp3"): |
| 27 | + Playlist.insert(END, song) |
| 28 | + |
| 29 | + |
| 30 | +def PlayMusic(): |
| 31 | + Music_Name = Playlist.get(ACTIVE) |
| 32 | + print(Music_Name[0:-4]) |
| 33 | + mixer.music.load(Playlist.get(ACTIVE)) |
| 34 | + mixer.music.play() |
| 35 | + |
| 36 | + |
| 37 | +# icon |
| 38 | +image_icon = PhotoImage( |
| 39 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/logo.png") |
| 40 | +root.iconphoto(False, image_icon) |
| 41 | + |
| 42 | +Top = PhotoImage( |
| 43 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/top.png") |
| 44 | +Label(root, image=Top, bg="#0f1a2b").pack() |
| 45 | + |
| 46 | +# logo |
| 47 | +logo = PhotoImage( |
| 48 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/logo.png") |
| 49 | +Label(root, image=logo, bg="#0f1a2b", bd=0).place(x=70, y=115) |
| 50 | + |
| 51 | +# Button |
| 52 | +ButtonPlay = PhotoImage( |
| 53 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/play.png") |
| 54 | +Button(root, image=ButtonPlay, bg="#0f1a2b", bd=0, |
| 55 | + command=PlayMusic).place(x=100, y=400) |
| 56 | + |
| 57 | +ButtonStop = PhotoImage( |
| 58 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/stop.png") |
| 59 | +Button(root, image=ButtonStop, bg="#0f1a2b", bd=0, |
| 60 | + command=mixer.music.stop).place(x=30, y=500) |
| 61 | + |
| 62 | +ButtonResume = PhotoImage( |
| 63 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/resume.png") |
| 64 | +Button(root, image=ButtonResume, bg="#0f1a2b", bd=0, |
| 65 | + command=mixer.music.unpause).place(x=115, y=500) |
| 66 | + |
| 67 | +ButtonPause = PhotoImage( |
| 68 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/pause.png") |
| 69 | +Button(root, image=ButtonPause, bg="#0f1a2b", bd=0, |
| 70 | + command=mixer.music.pause).place(x=200, y=500) |
| 71 | + |
| 72 | +# Label |
| 73 | +Menu = PhotoImage( |
| 74 | + file="C:/Users/HP/Desktop/Programs/Python-project-Scripts/PYTHON APPS/mp3-MusicPlayer/menu.png") |
| 75 | +Label(root, image=Menu, bg="#0f1a2b").pack(padx=10, pady=50, side=RIGHT) |
| 76 | + |
| 77 | +Frame_Music = Frame(root, bd=2, relief=RIDGE) |
| 78 | +Frame_Music.place(x=330, y=350, width=560, height=200) |
| 79 | + |
| 80 | +Button(root, text="Open Folder", width=15, height=2, font=("arial", |
| 81 | + 10, "bold"), fg="Black", bg="#21b3de", command=AddMusic).place(x=330, y=300) |
| 82 | + |
| 83 | +Scroll = Scrollbar(Frame_Music) |
| 84 | +Playlist = Listbox(Frame_Music, width=100, font=("Aloja", 10), bg="#000000", |
| 85 | + fg="white", selectbackground="lightblue", cursor="hand2", bd=0, yscrollcommand=Scroll.set) |
| 86 | +Scroll.config(command=Playlist.yview) |
| 87 | +Scroll.pack(side=RIGHT, fill=Y) |
| 88 | +Playlist.pack(side=LEFT, fill=BOTH) |
| 89 | + |
| 90 | +# Execute Tkinter |
| 91 | +root.mainloop() |
0 commit comments