Python 我怎样才能使一块椭圆形的画布围绕一个圆圈旋转呢

Python 我怎样才能使一块椭圆形的画布围绕一个圆圈旋转呢,python,tkinter,canvas,Python,Tkinter,Canvas,求你了,我想做一个椭圆形的画布绕着一个圆圈旋转。我尽了最大的努力,但不知道怎么做。有人能帮我吗。查看代码 from tkinter import * import time import math root=Tk() width=700 height=600 cn=Canvas(root,width=width,height=width) cn.pack(expand=True,fill="both") ball1=cn.create_oval(200,200,500,

求你了,我想做一个椭圆形的画布绕着一个圆圈旋转。我尽了最大的努力,但不知道怎么做。有人能帮我吗。查看代码

from tkinter import *
import time
import math


root=Tk()
width=700
height=600
cn=Canvas(root,width=width,height=width)
cn.pack(expand=True,fill="both")

ball1=cn.create_oval(200,200,500,500)
ball2=cn.create_oval(200,200,300,300,fill="black")
ball3=cn.create_oval(330,330,370,370,fill="black")
l1=cn.create_line(350,180,350,600)
l2=cn.create_line(180,350,600,350)
pos1=cn.coords(ball3)

rect=cn.create_rectangle(100,100,700,600)

root.mainloop()

我想让大一点的球沿着圆圈的线移动,这似乎是一个简单的数学问题,只要找到圆圈的中心,让bbox就可以了,使用
坐标移动它:

from tkinter import *
import time
import math


def moveCircle(angle=[0.0]):
    r = 50
    R = 150
    center_x, center_y = R * math.cos(math.radians(angle[0])) + 350, R * math.sin(math.radians(angle[0])) + 350
    cn.coords(ball2, center_x-r, center_y-r, center_x+r, center_y+r)
    angle[0] += 1.0
    root.after(100, moveCircle)

root = Tk()
width = 700
height = 600
cn = Canvas(root, width=width, height=width)
cn.pack(expand=True, fill="both")

ball1 = cn.create_oval(200, 200, 500, 500)
ball2 = cn.create_oval(200, 200, 300, 300, fill="black")
ball3 = cn.create_oval(330, 330, 370, 370, fill="black")
l1 = cn.create_line(350, 180, 350, 600)
l2 = cn.create_line(180, 350, 600, 350)

rect = cn.create_rectangle(100, 100, 700, 600)

root.after(10, moveCircle)
root.mainloop()
输出示例:

r
r
中,您还可以更改值以查看更改:

这似乎是一道简单的数学题,只要找到圆心并找到bbox就可以了,使用
坐标移动它:

from tkinter import *
import time
import math


def moveCircle(angle=[0.0]):
    r = 50
    R = 150
    center_x, center_y = R * math.cos(math.radians(angle[0])) + 350, R * math.sin(math.radians(angle[0])) + 350
    cn.coords(ball2, center_x-r, center_y-r, center_x+r, center_y+r)
    angle[0] += 1.0
    root.after(100, moveCircle)

root = Tk()
width = 700
height = 600
cn = Canvas(root, width=width, height=width)
cn.pack(expand=True, fill="both")

ball1 = cn.create_oval(200, 200, 500, 500)
ball2 = cn.create_oval(200, 200, 300, 300, fill="black")
ball3 = cn.create_oval(330, 330, 370, 370, fill="black")
l1 = cn.create_line(350, 180, 350, 600)
l2 = cn.create_line(180, 350, 600, 350)

rect = cn.create_rectangle(100, 100, 700, 600)

root.after(10, moveCircle)
root.mainloop()
输出示例:

r
r
中,您还可以更改值以查看更改:

谢谢。正是我想要的,我知道R是弧度,R呢?或者你能给我解释得更详细一点吗?谢谢,我从早上就开始尝试了。即使用三角函数,也无济于事。我现在明白了,谢谢。正是我想要的,我知道R是弧度,R呢?或者你能给我解释得更详细一点吗?谢谢,我从早上就开始尝试了。即使用三角函数,也无济于事。我现在明白了