【发布时间】:2019-05-02 20:02:44
【问题描述】:
所以我想在窗口底部放置一个矩形。如何找到正确的 y 坐标?我的窗口是全屏打开的,所以 y 坐标并不总是相同的。
由于我对 python 使用的数学不太了解,而且有时我会为我的问题找到奇怪的解决方案,因此我尝试使用整数。当然,我用谷歌搜索了我的问题,但找不到有效的解决方案。
from tkinter import *
def run(): #I define it, so I can import it and use it in other files.
w=Tk()
w.state('zoomed')
w.title('A title')
bg=Canvas(w,bg='#808080',borderwidth=0,highlightthickness=0)
bg.pack(fill='both',expand=True)
ywindow=w.winfo_screenheight()
yfooter=ywindow-30
footer=Canvas(w,bg='#A5A5A5',borderwidth=2,highlightthickness=0)
footer.place(height=30,width=w.winfo_screenwidth(),x=0,y=yfooter)
run()
我希望 tkinter 使用距离边界 30 像素的坐标作为 y,但它根本不显示 Canvas。
【问题讨论】:
-
如果你想要它在底部,否则在同一个容器中使用
.pack(),那么只需使用.pack(side=BOTTOM)。 -
你是问放置矩形,还是问放置cnavas?如果您询问有关画布的问题,请阅读
place上的文档。您可以指定相对于边缘的坐标。
标签: python tkinter tkinter-canvas tkinter-layout