import tkinter as tk
def rotate_taiji(canvas:tk.Canvas,angle):
#清空画布
canvas.delete("all")
x=canvas.winfo_width()//2
y=canvas.winfo_height()//2
#绘制半圆
canvas.create_arc(x-100,y-100,x+100,y+100,start=90+angle,fill='black',outline='black')
canvas.create_arc(x-100,y-100,x+100,y+100,start=270+angle,extent=180,fill='white',outline='white')
#绘制小圆
canvas.create_oval(x-30,y-30,x+30,y+30,fill='black',outline='black')
canvas.create_oval(x-30,y-130,x+30,y-70,fill='white',outline='white')
#更新角度并下一次旋转
angle+=10
canvas.after(10,rotate_taiji,canvas,angle)
root=tk.Tk()
root.geometry("800x700+400+50")
canvas=tk.Canvas(root,width=400,height=400)
canvas.pack()
canvas2=tk.Canvas(root,width=300,height=300,bg='cyan')
canvas2.pack(side=tk.BOTTOM,anchor='w')
rotate_taiji(canvas2,90)
rotate_taiji(canvas,0)
root.mainloop()
import tkinter as tk
def update_rectangle(value):
value = int(value) # 将滑动条的值转换为整数
canvas.coords(rectangle, 0, 200-value, 100, 200)
canvas.itemconfig(rectangle, fill="blue")
if __name__ == "__main__":
root = tk.Tk()
# 创建Canvas组件
canvas = tk.Canvas(root, width=110, height=210)
canvas.pack()
# 绘制矩形
rectangle = canvas.create_rectangle(5, 5, 105, 205, fill="blue")
rec=canvas.create_rectangle(3,3,110,210,outline='red')
# 创建滑动条
scale = tk.Scale(root, from_=0, to=200, orient=tk.HORIZONTAL, command=update_rectangle)
scale.pack()
root.mainloop()