#Sinewheel hip-pocket program in Python/Tkinter #William Baker, Summer 2004, illiMath04 Program #Adapted from Math198 course notes by Prof. George Francis #University of Illinois Urbana-Champaign Dept. of Mathematics import Tkinter import math import time defaldelay=4 #default delay time #createLine() #Draws a red line for the specified coordinates def createLine(canvas, x0, y0, x1, y1): canvas.create_line(x0, y0, x1, y1, fill="red") #startAnimation() #Actually performs the animation, called when the start button is #clicked def startAnimation(): dg = .01745 dx = 6 r = 75 #radius x0=80 y0=240 x=0 for x in range(0, 361, dx): # compute values xr=x0+r*math.cos(x*dg) yr = y0 -r*math.sin(x*dg) xx=x0+r+r*x*dg createLine(canvas,x0,y0,xr,yr) createLine(canvas,xr,yr,xx,yr) createLine(canvas,xx,yr,xx,y0) canvas.update() time.sleep(int(timedelay.get())/20.0) #clear() #Clears the cavas, called when clear button is clicked def clear(): canvas.delete("all") window = Tkinter.Tk() window.title("Sinewheel in Python/Tkinter") clear_button = Tkinter.Button(window, text = "Clear", command = clear) start = Tkinter.Button(window, text="Start", command=startAnimation) delLabel=Tkinter.Label(window, width="15") delLabel.configure(text="Time Delay= ") timedelay=Tkinter.StringVar() timedelay.set(`defaldelay`) delentry = Tkinter.Entry(window, width="15", textvariable=timedelay) canvas = Tkinter.Canvas(window, width=640, height=480) canvas.pack(side="top") delLabel.pack(side="left") delentry.pack(side="left") start.pack(side="right") clear_button.pack(side = "right") # start event loop window.mainloop()