简体   繁体   中英

Drawing a clock that prints the current time with python

i am supposed to draw a clock in python without using any modules that need downloading like turtle module, rather id have to use the stddraw module. The clock would also have to give the current time in hours, minutes, and seconds represented on the clock. I am struggling to understand how i'm supposed to go about doing this since i havent done any drawing or anything before so this is really new territory in terms of programming. Any ideas on how to go about doing this or advice is greatly appreciated!

without using any modules that need downloading like turtle module, rather id have to use the stddraw module

As @PurpleIce starts to get at, you've got this backward. The turtle module comes with Python, the stddraw module needs to be downloaded (from Princeton.)

Your question has inspired me to see if it is possible to make a minimalist working clock using Python turtle:

from time import localtime
from turtle import *  # avoid wildcard imports like this

ATTRIBUTES = ['tm_hour', 'tm_min', 'tm_sec']

def tick():
    record = localtime()

    hands['tm_hour'].seth(record.tm_hour % 12 * 30 + record.tm_min / 2 + record.tm_sec / 120)
    hands['tm_min'].seth(record.tm_min * 6 + record.tm_sec / 10)
    hands['tm_sec'].seth(record.tm_sec * 6)

    ontimer(tick, 1000)

mode("logo")  # make 0 degrees be straight up the page

hands = {}
for size, attr in enumerate(ATTRIBUTES, start=1):
    hands[attr] = Turtle('triangle')
    hands[attr].shapesize(1 / size, size * 10)

tick()

mainloop()

Hopefully, this will give you insight on how to begin building your own clock using the stddraw module:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM