[英]How can I make separator in Tkinter fill whole window height?
我想使用.place()
function 將從 window 頂部到底部的分隔符放置在特定位置。 當我這樣做時,分隔符只是一個小點。 我設法用.pack()
function 做到了,但它不在所需的位置。 我在互聯網上搜索,但找不到使用.place()
的解決方案,只有.pack()
和.grid()
。 它只是一個點而不是從上到下的線。
from tkinter import *
from tkinter import ttk
App = Tk()
ttk.Separator(App, orient=VERTICAL).place(x=275, y=0)
App.mainloop()
是否可以使用.place()
來做到這一點,如果是(可能是)怎么做?
我正在使用 Python 3.6
我知道的最簡單的解決方案是在place()
調用中指定height=
像素:
from tkinter import *
from tkinter import ttk
App = Tk()
App.geometry('1000x100')
ttk.Separator(App, orient=VERTICAL).place(x=275, y=0, height=100)
App.mainloop()
也可以將其與自動高度檢測配對:
from tkinter import *
from tkinter import ttk
App = Tk()
App.update()
ttk.Separator(App, orient=VERTICAL).place(x=50, y=0, height=App.winfo_height())
App.mainloop()
並且,動態更新:
from tkinter import *
from tkinter import ttk
App = Tk()
sep = ttk.Separator(App, orient=VERTICAL)
sep.place(x=50, y=0, height=App.winfo_height())
App.bind('<Configure>', lambda e: sep.place(x=50, y=0, height=App.winfo_height()))
App.mainloop()
希望這會有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.