#! /usr/bin/env python
# -*- coding: Utf-8 -*-

# Tkinter grafikus konyvtarat hasznalo alkalmazas

from Tkinter import *

# esmenykezelok definicioja :


def move():
    "labda elmozditasa"
    global x1, y1, dx, dy, flag
    x1, y1 = x1 +dx, y1 + dy
    if x1 >210:
        x1, dx, dy = 210, 0, 15
    if y1 >210:
        y1, dx, dy = 210, -15, 0
    if x1 <10:
        x1, dx, dy = 10, 0, -15
    if y1 <10:
        y1, dx, dy = 10, 15, 0
    can1.coords(oval1,x1,y1,x1+30,y1+30)
    if flag >0: 
        abl1.after(50,move)		# 50 msec mulva ujra hivja onmagat

def stop_it():
    "leallitja az animaciot"
    global flag    
    flag =0

def start_it():
    "inditja az animaciot"
    global flag
    if flag ==0:	# hogy ne lehessen több ciklust inditani
       flag =1
       move()

#========== Foprogram =============

# A kovetkezo valtozokat globalis valtozokkent hasznaljuk :
x1, y1 = 10, 10		# kiindulasi koordinatak
dx, dy = 15, 0		# elmozdulas merteke
flag =0			    # iranyvalto

# a fowidget letrehozasal ("szülo") :
abl1 = Tk()
abl1.title("Animációs gyakorlat Tkinter-rel")
# a "gyermek" widgetek letrehozasa :
can1 = Canvas(abl1,bg='dark grey',height=250, width=250)
can1.pack(side=LEFT, padx =5, pady =5)
oval1 = can1.create_oval(x1, y1, x1+30, y1+30, width=2, fill='red')
button1 = Button(abl1,text='Kilép', width =8, command=abl1.quit)
button1.pack(side=BOTTOM)
button2 = Button(abl1, text='Indít', width =8, command=start_it)
button2.pack()
button3 = Button(abl1, text='Leállít', width =8, command=stop_it)
button3.pack()
# esemenykezelo inditasa (fohurok) :
abl1.mainloop()

#bou -> button