title: Guess my number game and GUI = stumped :(
body: <p>I'm a beginner, and I'm having a real issue with incorporating a 'Guess my number game' into a GUI. This is a challenge from 'Python programming for the absolute beginner' and there are no solutions contained within the book?!</p>
  
  <p>I can get a single guess and run it through a while loop, but thereafter I'm at a loss. I've spent hours trying various things and have arrived at nothing which works. I'm probably way off track.</p>
  
  <p>I want to be able to get further guesses from the user, but how in a GUI?</p>
  
  <p>Thanks,
  Dave (tired and demoralized)</p>
  
  <pre><code>My code:
  
  # Guess my number game
  # User must attempt to guess randomly selected number within a range in fewest possible attempts
  
  from Tkinter import *
  import random
  
  class Application(Frame):
      """A GUI application which which generates random number and gets user input"""
  
      def __init__(self, master): #initialize newly created Application object
          """Initialize the frame"""
          Frame.__init__(self, master) # super(Application, self).__init__(master) in python 3
          self.grid()
          self.create_widgets()
  
  
      def create_widgets(self):
          """Get user inputs"""
          # create instruction label
          Label(self, text = "I'm thinking of a number between 1 and 100.").grid(row = 0, column = 0, sticky = W)
          Label(self, text = "Try and guess it in as few attempts as possible!").grid(row = 1, column = 0, sticky = W)
  
          # create guess input prompt label and entry
          Label(self, text = "Take a guess:").grid(row = 2, column = 0, sticky = W)
          self.guess_ent = Entry(self)
          self.guess_ent.grid(row = 2, column = 1, sticky = W)
  
          # create start game prompt label and submit button
          Label(self, text = "Press submit to start the game!").grid(row = 3, column = 0, sticky = W)
          Button(self, text = "Submit", command = self.run_game).grid(row = 3, column = 1, sticky = W)
  
  
          # create submit button
          #Button(self, text = "Submit", command = )
  
          # create computer feedback text box
          self.text = Text(self, width = 75, height = 10, wrap = WORD)
          self.text.grid(row = 4, column = 0, columnspan = 4)
  
  
  
  
  
      def run_game(self):
          """Generate number and get user input"""
          guess = int(self.guess_ent.get())
          number = random.randint(1, 101)
  
          while guess and guess != number:
              print_text = ""
              print_text += "You guessed "
              print_text += str(guess)
              print_text += "."
  
              if guess &gt; number:
                  print_text += " That's too high. Guess lower..."
              elif guess &lt; number:
                  print_text += " That's too low. Guess higher..."
  
              self.text.delete(0.0, END)
              self.text.insert(0.0, print_text)
  
              self.guess_ent.delete(0, END)
  
  
  
          #print_text = ""    
          #print_text += "That's the right number! Well done!"
          #self.text.delete(0.0, END)
          #self.text.insert(0.0, print_text)
  
  
  # main
  root = Tk()
  root.title("Guess my number game!")
  app = Application(root)
  root.mainloop()
  </code></pre>