dist2.py 898 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from Tkinter import *

       

root = Tk()

canvas = Canvas(root, bg="white", width=800, height= 300)

      # All of this would do better as a subclass of Canvas with specialize methods

       

def drawcircle(canv,x,y,rad):

      # changed this to return the ID

    return canv.create_oval(x-rad,y-rad,x+rad,y+rad,width=0,fill='blue')

       

def movecircle(canv, cir):

    canv.move(cir,-1,-1)

       

def callback(event):

      movecircle(canvas, circ1)

      movecircle(canvas, circ2)

       

      canvas = Canvas(width=600, height=200, bg='white')

      canvas.bind("<Button-1>", callback)

      canvas.pack(expand=YES, fill=BOTH)

       



text = canvas.create_text(50,10, text="tk test")

       

      #i'd like to recalculate these coordinates every frame

circ1=drawcircle(canvas,100,100,20)

circ2=drawcircle(canvas,500,100,20)

       
canvas.pack()
root.mainloop()