Guest User

Untitled

a guest
Mar 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. from pygame import *
  2. from Tkinter import *
  3. import time
  4. root = Tk()
  5. root.geometry("1000x200")
  6. root.title("sampler")
  7. m=1
  8. n=1
  9. mixer.init()
  10. def play():
  11.  
  12. while m==1:
  13.  
  14. print 'playing'
  15. mixer.music.load('audio 1.mp3')
  16. mixer.music.play()
  17. time.sleep(n)
  18.  
  19. start = Button(root, text="play", command = play)
  20. start.pack()
  21. stop = Button(root, text="Stop")
  22. stop.pack()
  23. mainloop()
  24.  
  25. from Tkinter import *
  26. from pygame import *
  27. import time
  28. import threading
  29.  
  30. switch = True
  31. root = Tk()
  32. n = 1
  33. mixer.init()
  34. root.geometry("1000x200")
  35. root.title("sampler")
  36.  
  37.  
  38. def play():
  39. def run():
  40. while switch:
  41. print 'playing'
  42. mixer.music.load('audio 1.mp3')
  43. mixer.music.play()
  44. time.sleep(n)
  45. if not switch:
  46. break
  47.  
  48. thread = threading.Thread(target=run)
  49. thread.start()
  50.  
  51.  
  52. def switch_on():
  53. global switch
  54. switch = True
  55. play()
  56.  
  57.  
  58. def switch_off():
  59. global switch
  60. switch = False
  61.  
  62.  
  63. def kill():
  64. root.destroy()
  65.  
  66.  
  67. onbutton = Button(root, text="Play", command=switch_on)
  68. onbutton.pack()
  69. offbutton = Button(root, text="Stop", command=switch_off)
  70. offbutton.pack()
  71. killbutton = Button(root, text="Kill", command=kill)
  72. killbutton.pack()
  73.  
  74. root.mainloop()
  75.  
  76. from pygame import *
  77. from tkinter import * # Change to "from Tkinter import *" for Python 2.x.
  78.  
  79. class PlayController(object):
  80. def __init__(self, mixer, music_filename, polling_delay):
  81. self.mixer = mixer
  82. self.music_filename = music_filename
  83. self.polling_delay = polling_delay
  84. self.playing = False
  85.  
  86. def play(self):
  87. if self.playing:
  88. self.stop()
  89. self.mixer.music.load(self.music_filename)
  90. self.mixer.music.play(-1) # -1 means to loop indefinitely.
  91. self.playing = True
  92.  
  93. def stop(self):
  94. if self.playing:
  95. self.mixer.music.stop()
  96. self.playing = False
  97.  
  98. root = Tk()
  99. root.geometry("1000x200")
  100. root.title("Sampler")
  101. mixer.init()
  102.  
  103. play_control = PlayController(mixer, 'tone.wav', 1000)
  104. Button(root, text="Play", command=play_control.play).pack()
  105. Button(root, text="Stop", command=play_control.stop).pack()
  106.  
  107. mainloop()
Add Comment
Please, Sign In to add comment