.create_rectangle()
是 Python 的 Tkinter 库中的一个函数,它可以在图形用户界面(GUI)中画一个矩形。
该函数的基本用法是在 Tkinter 的 Canvas 组件上调用 create_rectangle()
方法,并传入四个参数:
canvas.create_rectangle(x0, y0, x1, y1, options...)
其中,x0
和 y0
表示矩形左上角的坐标,x1
和 y1
表示矩形右下角的坐标。如果想要更复杂的矩形,还可以使用 options
参数指定矩形的各种属性,如颜色、线条宽度等。
示例代码:
from tkinter import *
root = Tk()
canvas = Canvas(root, width=200, height=100)
canvas.pack()
new_rectangle = canvas.create_rectangle(25, 25, 150, 75, fill="blue")
root.mainloop()
这段代码会在 GUI 界面中画出一个蓝色的矩形。