title: Ignore other Mouse Clicks, Graphics.py Python
body: <p>so I have the code where if the user clicks on the rectangle or button that says &quot;Calculate&quot; it'll do everything correctly.  However, how do I write a code that will ignore all other clicks until they click inside the rectangle or &quot;Calculate&quot;  I tried using while loops but I just can't get it to work.  I was wondering if anyone was able to help me with my issue.</p>
  <p>Here is my code:</p>
  <pre><code>from graphics import *
  
  def main():
  win = GraphWin(&quot;Body Mass Index Calculator&quot;, 500, 400)
  win.setCoords(0.0, 0.0, 3.0, 4.0)
  
  
  # Draw the interface
  Text(Point(1,3.5), &quot;   Height:&quot;).draw(win)
  Text(Point(1.66,3.5), &quot;   ft&quot;).draw(win)
  Text(Point(2.56,3.5), &quot;   inches&quot;).draw(win)
  
  
  Text(Point(1,2.8), &quot;   Weight:&quot;).draw(win)
  Text(Point(1.69,2.8), &quot;   lbs&quot;).draw(win)
  
  Text(Point(1.5,1), &quot;BMI:&quot;).draw(win)
  
  Text(Point(0.5, 1.5), &quot;BMI Categeories:&quot;).draw(win)
  under = Text(Point(0.56, 1.3), &quot;Underweight - &lt; 18.5&quot;).draw(win)
  normal = Text(Point(0.65, 1.1), &quot;Normal - &gt; 18.5 and &lt; 25&quot;).draw(win)
  over = Text(Point(0.71, 0.9), &quot;Overweight - &gt;= 25 and &lt; 30&quot;).draw(win)
  obese = Text(Point(0.4, 0.7), &quot;Obese - &gt; 30&quot;).draw(win)
  
  
  #for height, inches and ft
  #ft
  input1 = Entry(Point(1.5,3.5), 5)
  input1.setText(&quot;0.0&quot;)
  input1.draw(win)
  
  #inch
  input2 = Entry(Point(2.3,3.5), 5)
  input2.setText(&quot;0.0&quot;)
  input2.draw(win)
  
  #for weight in lbs  
  input3 = Entry(Point(1.5,2.8), 5)
  input3.setText(&quot;0.0&quot;)
  input3.draw(win)
  
  
  #calculate box
  output = Text(Point(2.1,1),&quot;&quot;)
  output.draw(win)
  button = Text(Point(1.5,2.0),&quot;Calculate&quot;)
  button.draw(win)
  rPoint1 = Point(1, 1.7)
  rPoint2 = Point(2,2.3)
  rec = Rectangle(rPoint1, rPoint2)
  rec.draw(win) 
  
  
  #wait for a mouse click
  p = win.getMouse()
  #convert
  ft = float(input1.getText()) * 12
  inch = float(input2.getText())
  height = ft + inch
  weight = float(input3.getText())
  bmi = (703*weight) / (height**2)
  
  #mouse click inside the calculate button
  
  if (p.getX() &gt; rPoint1.getX()) and (p.getX() &lt; rPoint2.getX()):
      if (p.getY() &gt; rPoint1.getY()) and (p.getY() &lt; rPoint2.getY()):
          if bmi &lt; 18.5:
              under.setFill(&quot;red&quot;)
              output.setText(str(bmi))
              button.setText(&quot;Quit&quot;)
  
              if (p.getX() &gt; rPoint1.getX()) and (p.getX() &lt; rPoint2.getX()):
                  if (p.getY() &gt; rPoint1.getY()) and (p.getY() &lt; rPoint2.getY()):
                      # wait for click and then quit
                      win.getMouse()
                      win.close()
                      
          elif bmi &gt;= 18.5 and bmi &lt; 25:
              normal.setFill(&quot;green&quot;)
              output.setText(str(bmi))
              button.setText(&quot;Quit&quot;)
  
              if (p.getX() &gt; rPoint1.getX()) and (p.getX() &lt; rPoint2.getX()):
                  if (p.getY() &gt; rPoint1.getY()) and (p.getY() &lt; rPoint2.getY()):
                      # wait for click and then quit
                      win.getMouse()
                      win.close()
                      
          elif bmi &gt;= 25 and bmi &lt; 30:
              over.setFill(&quot;orange&quot;)
              output.setText(str(bmi))
              button.setText(&quot;Quit&quot;)
  
              if (p.getX() &gt; rPoint1.getX()) and (p.getX() &lt; rPoint2.getX()):
                  if (p.getY() &gt; rPoint1.getY()) and (p.getY() &lt; rPoint2.getY()):
                      # wait for click and then quit
                      win.getMouse()
                      win.close()
                      
          elif bmi &gt; 30:
              obese.setFill(&quot;red&quot;)
              output.setText(str(bmi))
              button.setText(&quot;Quit&quot;)
          
  
              if (p.getX() &gt; rPoint1.getX()) and (p.getX() &lt; rPoint2.getX()):
                  if (p.getY() &gt; rPoint1.getY()) and (p.getY() &lt; rPoint2.getY()):
                      # wait for click and then quit
                      win.getMouse()
                      win.close()
  
  main()
  </code></pre>