天给大家分享 1 个非常实用的 python 技能——用 Python 做个能挂墙上的大钟表,先上成果视频:
本项目用到的库主要有 pygame 、 math 、 datetime 等,另外还用到一些数学知识,勾股定理搞不明白的朋友就不要往下看了,可能会头晕。
第一步:用 pygame 画个圆
1. 初始化画布参数
设置画布大小,添加标题,设置圆的原点、半径和角度:
加python学习qq群:775690737 送python零基础入门学习资料+99个源码
pygame.init()
screen = pygame.display.set_mode((
600 , 500
))
pygame.display.set_caption(
"挂墙上的大钟表"
)
pos_x =
300 ; pos_y = 250
#原点坐标
radius = 200
#半径
angle = 360 #角度
2. 画 1 个黑色边框的圆 :
while True
:
screen.fill((
255 , 255 , 255 ))
# 画布底色为白色
for event in
pygame.event.get():
if
event.type== QUIT:
sys.exit()
keys = pygame.key.get_pressed()