[Tutor] Wiget

ryan luna ryan_gm at sbcglobal.net
Fri Jun 30 06:23:17 CEST 2006


Hey everyone, im just learning to use Tkinter, and im trynig to write a
"Guess my number" game program in widget forum but im having some problems,
First heres the code im using,

Button(self,
               text = "Sumit",
               command = self.number_anwser
              ).grid(row = 4, column = 0, sticky = W)
        
        self.response_txt = Text(self, width = 50, height = 5, wrap = WORD)
        self.response_txt.grid(row = 5, column = 0, columnspan = 4)
    
    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)
        

the_number = random.randrange(100) + 1
root = Tk()
root.title("Guess my number GUI")
app = Application(root)
root.mainloop()

The problem is at the end where i try and get the number of Tries the user has tried it would just reset everytime the button in clicked, so my question is how would i go about getting the number of times the button is clicked and the anwser is wrong.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060629/2fe04426/attachment.htm 


More information about the Tutor mailing list