日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python编写时钟代码_python编写时钟代码

發(fā)布時(shí)間:2023/12/14 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编写时钟代码_python编写时钟代码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

# !/urs/bin/ python

# _*_ coding: utf-8

# !/usr/bin/env python

# -*- coding:utf-8 -*-

import turtle

import datetime

# 移動(dòng)一段距離

def skip(distance):

"""

移動(dòng)烏龜一段距離,不留痕跡

:param distance: 像素

:return:

"""

turtle.penup()

turtle.forward(distance)

turtle.pendown()

def draw_clock():

# 先畫表盤

# 先畫點(diǎn)

# 移動(dòng)一段距離,畫一個(gè)點(diǎn),然后退回

# 轉(zhuǎn)動(dòng)6°,再移動(dòng)一段距離,畫一個(gè)點(diǎn),然后退回

# 循環(huán) 60次

# 讓烏龜?shù)姆较蚰J(rèn)向上

turtle.reset()

turtle.hideturtle()

for i in range(60):

skip(160)

# 根據(jù) 5格一個(gè)時(shí)鐘

if i % 5 == 0:

turtle.pensize(7)

# 畫時(shí)鐘

turtle.forward(20)

if i == 0:

turtle.write(12, align='center', font=('Courier', 14, 'bold'))

elif i == 25 or i == 30 or i == 35:

skip(25)

turtle.write(int(i / 5), align='center', font=('Courier', 14, 'bold'))

skip(-25)

else:

turtle.write(int(i / 5), align='center', font=('Courier', 14, 'bold'))

skip(-20)

else:

turtle.pensize(1)

turtle.dot()

skip(-160)

turtle.right(6)

def get_week(t):

week = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']

return week[t.weekday()]

def create_hand(length, name):

turtle.reset()

skip(-length * 0.1)

turtle.begin_poly()

turtle.forward(length * 1.1)

turtle.end_poly()

# 注冊(cè)

turtle.register_shape(name, turtle.get_poly())

hand = turtle.Turtle()

hand.shape(name)

hand.shapesize(1, 1, 3)

return hand

def run():

# 不停的獲取時(shí)間

t = datetime.datetime.today()

bob.forward(65)

bob.write(get_week(t), align='center', font=('Courier', 14, 'bold'))

bob.back(130)

bob.write(t.strftime('%Y-%m-%d'), align='center', font=('Courier', 14, 'bold'))

bob.home()

# 指針移動(dòng)

second = t.second + t.microsecond * 0.000001

minute = t.minute + second / 60

hour = t.hour + minute / 60

turtle.tracer(True)

second_hand.setheading(6 * second)

minute_hand.setheading(6 * minute)

hour_hand.setheading(30 * hour)

turtle.ontimer(run, 200)

if __name__ == '__main__':

# 畫秒針,分針,時(shí)針

turtle.mode('logo')

turtle.hideturtle()

global second_hand, minute_hand, hour_hand, bob

second_hand = create_hand(135, 'second_hand')

minute_hand = create_hand(125, 'minute_hand')

hour_hand = create_hand(90, 'hour_hand')

# 創(chuàng)建一個(gè)新的turtle對(duì)象,去循環(huán)的操作

bob = turtle.Turtle()

bob.hideturtle()

bob.penup()

turtle.tracer(False)

draw_clock()

run()

turtle.mainloop()

總結(jié)

以上是生活随笔為你收集整理的python编写时钟代码_python编写时钟代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。