ny = int(numbers / float(nx))
dy = (conf.WINHEIGHT - 100) / float(nx)
y0 = 20
nr = numbers - (nx * ny)
for y in range(ny):
for x in range(nx):
n = x + (nx * y) + 1
b = Button(self, n)
self.events.add(b.events)
self.buttons[n] = b
x1 = x0 + x * dx
y1 = y0 + y * dy
b.setPosition((x1, y1))
b.draw()
def erase_to(self, num):
d = Dialog_OK(message="%s is too low" % num)
d.modal()
for n in range(1, num+1):
try:
b = self.buttons[n]
b.clear()
b.events.disable()
del(self.buttons[n])
except KeyError:
pass
def erase_from(self, num):
d = Dialog_OK(message="%s is too high" % num)
d.modal()
for n in range(num, self.numbers+1):
try:
b = self.buttons[n]
b.clear()
b.events.disable()
del(self.buttons[n])
except KeyError:
pass
def victory(self):
d = Dialog_OK(message="Yes!\nThe correct number was %s" %
self.choice)
d.modal()
os._exit(0)
if __name__ == '__main__':
g = GuessingGame()
d = Dialog_OK(message="Guess the correct number")
d.modal()
g.mainloop()
#end guess.py
I am not sure if the Button really needs to know about the Game,
but I find that tends to happen pretty often. Maybe I could define
the callback in the Game, and pass that to the button... I should
probably study up on MVC myself :o)
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail