簡體   English   中英

如何在 Tkinter 中的 position TopLevel Window?

[英]How to position TopLevel Window in Tkinter?

我想 position 我的頂級 Window 就在我的根 Window 的右側。
像這樣的東西→❏❏

這是我的根 window 的代碼

root = Tk()
root.geometry("+100+100")
root.update() 
root_width = root.winfo_width()
root_height = root.winfo_height()
root_xoffset = root.winfo_x()
root_yoffset = root.winfo_y()

這是我的 TopLevel window 的代碼

newWindow = Toplevel(pady=10)
newWindow.geometry(f"+{root_width+root_xoffset}+{root_yoffset}")

您可以使用.winfo_x().winfo_width()來獲取頂層 window 的 offsetx。 喜歡:

import tkinter as tk

root = tk.Tk()

root.update() # to get the height and the offset of Tk window
toplevel = tk.Toplevel()
toplevel_offsetx, toplevel_offsety = root.winfo_x() + root.winfo_width(), root.winfo_y()
padx = 0 # the padding you need.
pady = 0
toplevel.geometry(f"+{toplevel_offsetx + padx}+{toplevel_offsety + pady}")
root.mainloop()

暫無
暫無

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

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