簡體   English   中英

我如何定義矩形的高度?

[英]how do i define the height of rectangle?

“創建一個坐標為 x1=15, y1=20, width=120, height=150 的矩形” 它是否與坐標有關? 因為沒有“高度”選項

from tkinter import *
window = Tk()
root.geometry("300x300")

canv = Canvas(window, width=200, height=250, bg="white")
canv.pack(pady=15)

coords = [15, 20, 0, 0]
rect = canvas.create_rectangle(coords, width=120)
window.mainloop()```

是的,您的coords定義了矩形[x1, y1, x2, y2]兩個對角的位置。 你已經有了左上角的坐標,所以你需要使用給定的高度和寬度來計算右下角的坐標——你只需將它們添加到坐標中。

在此示例中,您只需將坐標從[15, 20, 0, 0]更改為[15, 20, 135, 170]

需要注意的一點是,Tkinter 中的坐標系是用窗口左上角的 (0,0) 定義的,因此 y 坐標越高意味着窗口越靠下,而 x 坐標越高意味着越靠右。

坐標是您定義矩形的高度和寬度的方式。 不需要高度定義。

這是來自: https ://pythonguides.com/python-tkinter-canvas/

Python Tkinter 畫布矩形

Python Tkinter Canvas has built-in features to create shapes.
To create a rectangle create_rectangle() method is used.
This method accepts 4 parameters x1, y1, x2, y2. Here x1 and y1 are the coordinates for the top left corner and x2 and y2 are the coordinates for the bottom right corner.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM