绘制一个使用python打印当前时间的时钟 [英] Drawing a clock that prints the current time with python

查看:277
本文介绍了绘制一个使用python打印当前时间的时钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在python中画一个时钟而不使用任何需要下载的模块,例如turtle模块,而id必须使用stddraw模块。时钟还必须提供时钟上表示的小时,分​​钟和秒的当前时间。我正在努力了解应该如何去做,因为我之前没有做过任何绘图或其他任何工作,所以就编程而言,这确实是一个新领域。

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!

推荐答案


不使用任何建议,将不胜感激!需要下载的模块(例如乌龟模块,
而不是id)必须使用stddraw模块

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

@PurpleIce开始出现,您已经把这个倒退了。乌龟模块是Python附带的,需要下载stddraw模块(从Princeton。)

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.)

您的问题启发了我,看是否有可能使简约的作品成为可能使用Python乌龟计时:

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()

希望这将使您了解如何使用stddraw模块开始构建自己的时钟:

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

这篇关于绘制一个使用python打印当前时间的时钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆