title: Tkinter while loop guess game
body: <pre><code># Tkinter guessing game
  from tkinter import *
  import random
  
  
  window = Tk()
  
  # Bot Generator
  bot = random.randint(1, 20+1)
  print(bot)
  
  
  def submit():
      tries = 5
      while tries &gt;= 0:
          e1 = (int(guessE.get()))
          if e1 == bot:
              print(&quot;You win&quot;)
              break
              
          elif e1 != bot:
              print(&quot;Try again&quot;)
              tries -= 1
              break
  
  
  def clear():
      guessE.delete(0, &quot;end&quot;)
      
      
  # Guess Label
  guessL = Label(window, text=&quot;Guess a number (between 1 and 20}&quot;)
  guessL.place(x=75, y=50)
  
  # Guess Entry
  guessE = Entry(window, width=25, bg=&quot;lightgrey&quot;)
  guessE.place(x=95, y= 80)
  
  # Submit Button
  submitBtn = Button(window, width=10, height=2, text=&quot;Submit&quot;, command=submit)
  submitBtn.place(x=85, y=115)
  
  # Clear Button
  clearBtn = Button(window, width=10, height=2, text=&quot;Clear&quot;, command=clear)
  clearBtn.place(x=175, y=115)
  
  
  window.geometry(&quot;350x350&quot;)
  window.resizable(0, 0)
  window.attributes(&quot;-topmost&quot;, True)
  window.mainloop()
  </code></pre>
  <p>I am trying to create a guessing game with Tkinter, I have created all the entries and labels, the clear button is working. I am struggling with creating a while loop, I need the program to stop accepting submitted entries once 5 tries have been used. Any ideas on how I can solve this?</p>