Please find the attached code.Thanks
On 10/23/2015 11:11 am, vijayapr wrote:
Hi,
I am newbie writing a simple code to count the button press when
.wav file plays.
when i run .wav file using pygame in tkinter interface, I couldnot
able to access any key from keyboard.
I need to count the button press when audio is on.
Can you help me with this?
Thanks,
Vijay
On 10/19/2015 5:09 am, S Suresh wrote:
Hi,
we have few python developer openings in our company(ALTEN CALSOFTLABS
http://www.altencalsoftlabs.com/) , from junior to senior levels..
Requirements :
Strong python knowledge
Should be able to design, develop, automate & validate
Should be fast learner & adaptive
Capable of mentoring, guide the team
Interface with clients & understand the requirements
Desirable: HTML, Javascripts
if you are interested, Please share your CV to my mail id
sureshkuma...@calsoftlabs.com
Thanks
suresh.
_______________________________________________
Chennaipy mailing list
Chennaipy@python.org
https://mail.python.org/mailman/listinfo/chennaipy
from Tkinter import *
import pygame
import time, random
import os
class Application(Frame):
"""A GUI application with three button"""
global counter1
counter1 = 0
def __init__(self,master):
Frame.__init__(self,master)
self.master = master
self.create_widgets()
def create_widgets(self):
#"""Create three buttons"""
#Create first buttom
frame=Frame(self, width=500, height=400, bd=1)
frame.grid()
embed = Frame(frame)
embed.grid()
os.environ['SDL_WINDOWID'] = str(embed.winfo_id())
iframe5= Frame(frame, bd=2, relief=RAISED)
iframe5.grid(pady=10, padx=5)
c1 = Canvas(iframe5, width=200, height=100)
c1.grid(row=0, column= 1)
counter = StringVar()
self.w1 = Label(c1, text= str(counter1)+ '\nHITS', font = "Helvetica 16 bold italic", bg="red", fg="white", width = 15, height= 5)
self.w1.grid()
c2 = Canvas(iframe5, bg= 'green', width=20, height=100)
c2.grid(row=0, column=2)
self.w2 = Label(c2, text= str(counter1)+ '\nFALSE ALARM', font = "Helvetica 16 bold italic", bg="green", fg="black", width = 15, height= 5)
self.w2.grid()
c3 = Canvas(iframe5, bg= 'blue', width=200, height=100)
c3.grid(row=1, column=1)
self.w3 = Label(c3, text= str(counter1)+ '\nMISS', font = "Helvetica 16 bold italic", bg="blue", fg="white", width = 15, height= 5)
self.w3.grid()
c4 = Canvas(iframe5, bg= 'red', width=200, height=100)
c4.grid(row=1, column=2)
self.w4 = Label(c4, text= str(counter1)+ '\nCORRECT \nREJECTION', font = "Helvetica 16 bold italic", bg="brown", fg="white", width = 15, height= 5)
self.w4.grid()
btn1 = Button(self.master, text = "REACTION TIME")
btn1.grid()
#Create second button
btn2 = Button(self.master, text = "T do nothing as well")
btn2.grid()
#Create third button
btn3=Button(self, text = "CLICK ME", command= self.nClick)
btn3.grid(row=12, column = 0)
self.grid()
closeButton = Button(self, text="Close", command=self.close_window)
closeButton.grid(row=8, column=5)
okButton = Button(self, text="START TRIAL", command = self.play)
okButton.grid(row= 8, column = 0, padx=10, pady=5)
stopButton = Button(self, text = "STOP TRIAL", command=self.stop)
stopButton.grid()
def nClick(self):
global counter1
counter1 += 1
self.w1.config(text=str(counter1)+'\nHITS')
self.w2.config(text=str(counter1)+'\nFALSE ALARM')
self.w3.config(text=str(counter1)+'\nMISS')
self.w4.config(text=str(counter1)+'\nCORRECT \nREJECTION')
def close_window(self):
self.master.destroy()
def play(self):
pygame.init()
END_MUSIC_EVENT = pygame.USEREVENT
pygame.mixer.music.set_endevent(END_MUSIC_EVENT)
i = [1.0,0.9,0.8,0.7,0.6,0.5,0.4,0.3,0.2]
pygame.mixer.music.load('C:/users/vijayapr/desktop/half.wav')
pygame.mixer.music.play()
while True:
for event in pygame.event.get():
if event.type == END_MUSIC_EVENT:
time.sleep(random.choice([2,3,4,5,6]))
i = i[1:]+[i[0]]
pygame.mixer.music.set_volume(float(i[0]))
pygame.mixer.music.load('C:/users/vijayapr/desktop/half.wav')
print "next volume"
pygame.mixer.music.play()
pygame.event.poll()
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
break
pygame.quit()
sys.exit()
def stop(self):
pygame.mixer.music.stop()
def main():
root = Tk()
root.title("Lazy Button 2")
root.geometry("500x500")
app = Application(root)
root.mainloop()
def close_window():
root.destroy()
if __name__ == '__main__':
main()
_______________________________________________
Chennaipy mailing list
Chennaipy@python.org
https://mail.python.org/mailman/listinfo/chennaipy