Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pygame import *
- from Tkinter import *
- import time
- root = Tk()
- root.geometry("1000x200")
- root.title("sampler")
- m=1
- n=1
- mixer.init()
- def play():
- while m==1:
- print 'playing'
- mixer.music.load('audio 1.mp3')
- mixer.music.play()
- time.sleep(n)
- start = Button(root, text="play", command = play)
- start.pack()
- stop = Button(root, text="Stop")
- stop.pack()
- mainloop()
- from Tkinter import *
- from pygame import *
- import time
- import threading
- switch = True
- root = Tk()
- n = 1
- mixer.init()
- root.geometry("1000x200")
- root.title("sampler")
- def play():
- def run():
- while switch:
- print 'playing'
- mixer.music.load('audio 1.mp3')
- mixer.music.play()
- time.sleep(n)
- if not switch:
- break
- thread = threading.Thread(target=run)
- thread.start()
- def switch_on():
- global switch
- switch = True
- play()
- def switch_off():
- global switch
- switch = False
- def kill():
- root.destroy()
- onbutton = Button(root, text="Play", command=switch_on)
- onbutton.pack()
- offbutton = Button(root, text="Stop", command=switch_off)
- offbutton.pack()
- killbutton = Button(root, text="Kill", command=kill)
- killbutton.pack()
- root.mainloop()
- from pygame import *
- from tkinter import * # Change to "from Tkinter import *" for Python 2.x.
- class PlayController(object):
- def __init__(self, mixer, music_filename, polling_delay):
- self.mixer = mixer
- self.music_filename = music_filename
- self.polling_delay = polling_delay
- self.playing = False
- def play(self):
- if self.playing:
- self.stop()
- self.mixer.music.load(self.music_filename)
- self.mixer.music.play(-1) # -1 means to loop indefinitely.
- self.playing = True
- def stop(self):
- if self.playing:
- self.mixer.music.stop()
- self.playing = False
- root = Tk()
- root.geometry("1000x200")
- root.title("Sampler")
- mixer.init()
- play_control = PlayController(mixer, 'tone.wav', 1000)
- Button(root, text="Play", command=play_control.play).pack()
- Button(root, text="Stop", command=play_control.stop).pack()
- mainloop()
Add Comment
Please, Sign In to add comment