Jump to content


Photo

Chapter 7


  • Please log in to reply
1 reply to this topic

#1 Mimi96

Mimi96

    New Member

  • Members
  • Pip
  • 2 posts

Posted 10 September 2014 - 06:32 AM

Hi guys. I have a problem running the last program from chapter 7. Here is my code:

 from tkinter import *

import pygame.mixer

def play_correct_sound():
    num_good.set(num_good.get() + 1)
    correct_s.play()

def play_wrong_sound():
    num_wrong.set(num_wrong.get() + 1)
    wrong_s.play()

app = Tk()
app.title("TVN Game Show")
app.geometry('300 x 110 + 200 + 100') 

sounds = pygame.mixer()
sounds.init()
correct_s = sounds.Sound("correct.wav")
wrong_s = sounds.Sound("wrong.wav")

num_good = IntVar()
num_good.set(0)
num_bad = IntVar(0)
num_bad.set(0)

lab = Label(app, text = 'When you are ready, click the button!', height = 3)
lab.pack()
lab1 = Label(app, textvariable = num_good)
lab1.pack(side = 'left')
lab2 = Label(app, textvariable = num_wrong)
lab2.pack(side = 'right')

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_wrong_sound)
b2.pack(side = 'right', padx = 10, pady = 10)

app.mainloop()
             


When I click Run Module, the following message appears:

Traceback (most recent call last):
File "C:\Users\mishka\Desktop\New folder (2)\gui.py", line 15, in <module>
app.geometry('300 x 110 + 200 + 100')
File "C:\Python34\lib\tkinter\__init__.py", line 1623, in wm_geometry
return self.tk.call('wm', 'geometry', self._w, newGeometry)
_tkinter.TclError: bad geometry specifier "300 x 110 + 200 + 100"

Can you help me? Thank you in advance. :)

Edited by Mimi96, 10 September 2014 - 06:42 AM.


#2 #TM#

#TM#

    Active Member

  • Members
  • PipPipPip
  • 91 posts
  • Gender:Not Telling

Posted 13 September 2014 - 05:35 AM

app.geometry('300 x 110 + 200 + 100')
Do not use spaces in between those operands and operators. i.e, it is not '300 x 110 + 200 + 100' but '300x110+200+100'


sounds = pygame.mixer()
Remove parentheses or you will get another error as pygame.mixer object is not callable.


def play_wrong_sound():
    num_wrong.set(num_wrong.get() + 1) # problem here**
    wrong_s.play()

num_bad = IntVar(0) # problem here**
num_bad.set(0)

lab2 = Label(app, textvariable = num_wrong) # problem here**
lab2.pack(side = 'right')

** Use either num_wrong or num_bad as the variable for counting of wrong answers Or you will get NameError saying num_wrong not defined






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users