Drawing a clock that prints the current time with python

ε祈祈猫儿з 提交于 2019-12-13 10:49:49

问题


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!


回答1:


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:



来源:https://stackoverflow.com/questions/52956592/drawing-a-clock-that-prints-the-current-time-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!