[Tutor] Wiget
John Fouhy
john at fouhy.net
Fri Jun 30 07:02:55 CEST 2006
On 30/06/06, ryan luna <ryan_gm at sbcglobal.net> wrote:
> def number_anwser(self):
> guess = self.guess_ent.get()
> guess = int(guess)
> response = ""
> tries = 1
>
> if (guess < the_number):
> response += "Higher"
> tries += 1
> elif (guess > the_number):
> response += "Lower"
> tries += 1
> else:
> tries = str(tries)
> response += "Correct! that was my number, \n"
> response += "You guessed it in just "
> response += tries
> response += " tries!"
>
> self.response_txt.delete(0.0, END)
> self.response_txt.insert(0.0, response)
This is the function that gets called whenever your button is clicked.
So, every time you click the button, "tries" gets set to 1.
I assume you have a class derived from Frame -- can you think how to
store your "tries" value in your Frame object?
(do you know the difference between local variables and object attributes?)
--
John.
More information about the Tutor
mailing list