title: Click on a button and advance to the limit of the window in tinker
body: <p>i am trying to learn python from a book. I'm trying to do an exercise with tinker. Click on a button and advance to the limit of the window. Then always by clicking on the same button to advance the circle to the other side of the window. Thanks for your help.</p>
  <pre><code>from tkinter import *
  
  def avance(n, g):
      global x, y, step
      # nouvelles coordonnées :
      x[n] = x[n] + g # deplacement de l'axe des x
      # déplacement du dessin dans le canevas :
      can.coords(bille[n], x[n]-10, y[n]-10, x[n]+10, y[n]+10)
  
      # affichage pour info du x:
      Info.configure(text=&quot;Coordonnée x = &quot; + str(x[n]))
      
      i = 0 
               
      if x[n] &gt;= 50:
          while i &lt;= 400:
              step = +20
              i = i+5
              
      if x[n] &gt;= 400:
          step = -20
          i = i-5
  
      return step          
  
      
  
  
  def go():
      avance(0, step)
  
  
  bille = [0]      # liste servant à mémoriser les références du cercle
  x = [50]     # X de départ
  y = [100]    # y de départ
  step = 0   # &quot;pas&quot; de déplacement initial
  
  # Construction de la fenêtre :
  fen = Tk()
  fen.title(&quot;avance quand on clique jusqu'à la limite de la fenêtre et revient&quot;)
  
  
  Info = Label(fen) # pour afficher l'info du x
  Info.grid(row=3, column=0)
  
  # Canvas :
  can = Canvas(fen, bg=&quot;white&quot;, width=400, height=200)
  can.grid(row=2, column=0, columnspan=2)
  bille[0] = can.create_oval(x[0]-10, y[0]-10, x[0]+10, y[0]+10,
                             fill=&quot;blue&quot;)
  
  # bouton avance :
  f = Frame(fen)
  f.grid(row=4, column=0, sticky=W, padx=10)
  
  Button(f, text=&quot;Go&quot;, fg='blue', command=go).pack(side=LEFT)
  
  fen.mainloop()
  </code></pre>
  <p>the problem is that when the ball reaches the limit (first while loop) when it starts the second loop, it returns to the conditions of the first.</p>
  <p>sorry for my English</p>
  <p>thank for help</p>