我有一个关于tkinter的新问题。我有我的功能:
rect = canvas.create_rectangle(10, 10, 50, 50, width=5, outline='black', fill='gray40', tags=('rect'))
如何使用bbox坐标将创建的矩形放置在画布上?我不知道如何比较我希望它可能的功能。我试着将它挂在最后一节,但它没有用。
功能是:
canvas.bbox()
canvas.bbox()
返回一份清单。您可以在调用canvas.create_rectangle()
时使用该列表。
这是一个绘制两个椭圆的程序示例,然后使用bbox
的结果绘制一个围绕它们的矩形:
import tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=400, background='white')
canvas.pack(fill="both", expand=True)
canvas.create_oval(10, 10, 50, 50, fill="red")
canvas.create_oval(30, 20, 80, 90, fill="blue")
bbox = canvas.bbox("all")
canvas.create_rectangle(bbox, outline="black")
root.mainloop()