Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python please help _______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ # an analog clock from tkinter import * import math def draw_clock(): w, h = 300, 300 # size of the

python please help _______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

# an analog clock

from tkinter import *

import math

def draw_clock():

w, h = 300, 300 # size of the canvas

x, y = w/2, h/2 # center of the canvas and the clock

size = 200 # size of the clock

circle1 = canvas.create_oval(x-size/2, y-size/2,

x+size/2, y+size/2,

fill='ivory')

circle2 = canvas.create_oval(x-size/2, y-size/2,

x+size/2, y+size/2,

width=3, outline='black')

ticks1, numbers = [], []

n = 12

for i in range(n):

angle = 2*math.pi*i/n

ticks1.append(canvas.create_line(x+100*math.cos(angle),

y+100*math.sin(angle),

x+90*math.cos(angle),

y+90*math.sin(angle),

fill='black', width=2))

numbers.append(canvas.create_text(x+80*math.cos(angle),

y+80*math.sin(angle), text=str((i+2)%n+1)))

ticks2 = []

n = 60

for i in range(n):

angle = 2*math.pi*i/n

ticks1.append(canvas.create_line(x+100*math.cos(angle),

y+100*math.sin(angle),

x+95*math.cos(angle),

y+95*math.sin(angle),

fill='black', width=1))

global time

time += 1 # add a time interval = 1 sec

alpha = 2*math.pi *(time % 60) /60

arrow1 = canvas.create_line(x,y,x+90*math.cos(alpha),y+90*math.sin(alpha),

fill='red', width=2, arrow='last')

gui.after(1000, lambda:draw_clock()) # update after 1000 msecs = 1 sec

# main program

gui = Tk()

canvas = Canvas(gui, height=300, width=300)

canvas.pack()

time = 0

draw_clock()

gui.mainloop()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Android Graphics

Authors: Wallace Jackson

1st Edition

1430257857, 978-1430257851

More Books

Students also viewed these Programming questions