我正在学习python,但我想不出这个简单的任务。我有一个带有文本的代码示例,我需要做同样的事情,但不是文本,而是一些形状(我现在需要标记->参见下图)。
谢谢您的解决方案!
我的代码:
import tkinter
import random
canvas = tkinter.Canvas(height = 500, width = 500, background = 'white')
canvas.pack()
for i in range(12):
canvas.create_text(250,250, text = 20*' '+'Python', font = 'Arial 25', angle = i*30)
tkinter.mainloop()
我需要以下代码的结果: https://imgur.com/ugdDhAg
答案 0 :(得分:0)
我设法自己找出了...如果有人需要这个:
import tkinter
import random
import math
canvas = tkinter.Canvas(height = 500, width = 500, background = 'white')
canvas.pack()
length = 150
Angle = 15
RadAngle = math.pi/180*Angle #degree in radians to use it with cos and sin
for i in range(24):
canvas.create_line(250,250,250+math.cos(i*RadAngle)*length,250+math.sin(i*RadAngle)*length,\
250+math.cos((i+1)*RadAngle)*(length-25),250+math.sin((i+1)*RadAngle)*(length-25),\
250+math.cos(i*RadAngle)*(length-50),250+math.sin(i*RadAngle)*(length-50))
tkinter.mainloop()