from Tkinter import * import pygame.mixer sounds = pygame.mixer sounds.init() correct_s = sounds.Sound("Correct.wav") wrong_s = sounds.Sound("Wrong.wav") number_correct = 0 number_wrong = 0 def play_correct_sound(): global number_correct number_correct = number_correct + 1 correct_s.play() def play_wrong_sound(): global number_wrong number_wrong = number_wrong + 1 wrong_s.play() app = Tk() # creat a tkinter application window called "app" app.title("TVN Game Show") app.geometry("300x100+200+100") b1 = Button(app, text = "Correct!", width = 10, command = play_correct_sound) b1.pack(side = "left", padx = 10, pady = 10) b2 = Button(app, text = "Wrong!", width = 10, command = play_correct_sound) b2.pack(side = "right", padx = 10, pady = 10) app.mainloop() print str(number_correct) + " were correctly answereed." print str(number_wrong) + " were answered incorrectly."
In the above program I'M having two problems. The first is there is no sound played when I run this code and click on the buttons. The sounds can be found at http://www.headfirstlabs.com/books/hfprog/ under chapter 7.
The second problem I'M having is the last line will only and always display "0" for answered incorrectly.
Thanks for any and all replies.