我有一个问题想请教大家
本帖最后由 1406598279 于 2021-2-3 12:54 编辑这个是我写的代码:
#导入
import turtle as t
import datetime as ti
#画出背景
game = t.Screen()
game.bgcolor('black')
game.setup(600,600)
#画圈
pen = t.Turtle()
pen.ht()
pen.speed(0)
pen.up()
pen.pensize(5)
def draw_clock(h,m,s):
pen.color('yellow')
pen.goto(0,-210)
pen.down()
pen.circle(210)
#画刻度
pen.up()
pen.goto(0,0)
pen.seth(90)
for i in range(12):
pen.fd(190)
pen.down()
pen.fd(20)
pen.up()
pen.goto(0,0)
pen.rt(30)
#画时针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(h/12*360)
pen.color('white')
pen.fd(80)
#画分针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(m/60*360)
pen.color('red')
pen.fd(120)
#画秒针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(s/60*360)
pen.color('blue')
pen.fd(160)
now = ti.datetime.now()
draw_clock(now.hour,now.min,now.second)
game. mainloop()
—————————————————————————————————————————————————分割线—————————————————————————————————————————————————
但是它弹出了一个错误:
Traceback (most recent call last):
File "C:\Users\14065\Desktop\Python\clock\time.py", line 63, in <module>
draw_clock(now.hour,now.min,now.second)
File "C:\Users\14065\Desktop\Python\clock\time.py", line 50, in draw_clock
pen.rt(m/60*360)
TypeError: unsupported operand type(s) for /: 'datetime.datetime' and 'int'
—————————————————————————————————————————————————分割线—————————————————————————————————————————————————
这是这个的视频教程:https://www.bilibili.com/video/BV1rJ411j795/?p=7&spm_id_from=pageDriver
我觉得可能是版本问题
请大家帮我!!!{:10_254:} import turtle as t
import datetime as ti
#画出背景
game = t.Screen()
game.bgcolor('black')
game.setup(600,600)
#画圈
pen = t.Turtle()
pen.ht()
pen.speed(0)
pen.up()
pen.pensize(5)
def draw_clock(h,m,s):
pen.color('yellow')
pen.goto(0,-210)
pen.down()
pen.circle(210)
#画刻度
pen.up()
pen.goto(0,0)
pen.seth(90)
for i in range(12):
pen.fd(190)
pen.down()
pen.fd(20)
pen.up()
pen.goto(0,0)
pen.rt(30)
#画时针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(h/12*360)
pen.color('white')
pen.fd(80)
#画分针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(m/60*360)
pen.color('red')
pen.fd(120)
#画秒针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(s/60*360)
pen.color('blue')
pen.fd(160)
now = ti.datetime.now()
draw_clock(now.hour,now.minute,now.second)
楼主传入参数错误,正确 代码如上 1q23w31 发表于 2021-2-3 17:37
楼主传入参数错误,正确 代码如上
真的可以了。非常感谢! @zltzlt @Twilight6
申请最佳
页:
[1]