Advertisement
skip420

music

Dec 29th, 2020 (edited)
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. # Music Player that loads,plays,pauses and plays ( Juke Box )Music player
  2.  
  3. # Tribute to Leo_
  4. #
  5. #
  6. #
  7. #  pip3 install pygame
  8. #
  9. from tkinter import *
  10. from tkinter import filedialog
  11. from pygame import mixer
  12.  
  13. class MusicPlayer:
  14.     def __init__(self, window ):
  15.         window.geometry('320x100'); window.title('Iris Player'); window.resizable(0,0)
  16.         Load = Button(window, text = 'Load',  width = 10, font = ('Times', 10), command = self.load)
  17.         Play = Button(window, text = 'Play',  width = 10,font = ('Times', 10), command = self.play)
  18.         Pause = Button(window,text = 'Pause',  width = 10, font = ('Times', 10), command = self.pause)
  19.         Stop = Button(window ,text = 'Stop',  width = 10, font = ('Times', 10), command = self.stop)
  20.         Load.place(x=0,y=20);Play.place(x=110,y=20);Pause.place(x=220,y=20);Stop.place(x=110,y=60)
  21.         self.music_file = False
  22.         self.playing_state = False
  23.     def load(self):
  24.         self.music_file = filedialog.askopenfilename()
  25.     def play(self):
  26.         if self.music_file:
  27.             mixer.init()
  28.             mixer.music.load(self.music_file)
  29.             mixer.music.play()
  30.     def pause(self):
  31.         if not self.playing_state:
  32.             mixer.music.pause()
  33.             self.playing_state=True
  34.         else:
  35.             mixer.music.unpause()
  36.             self.playing_state = False
  37.     def stop(self):
  38.         mixer.music.stop()
  39. root = Tk()
  40. app= MusicPlayer(root)
  41. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement