Python 我怎样才能使Tkinter中的分隔符填充整个窗口高度?

Python 我怎样才能使Tkinter中的分隔符填充整个窗口高度?,python,tkinter,Python,Tkinter,我想使用.place()函数将分隔符从窗口顶部到底部放置在特定位置。当我这样做时,分隔符只是一个小点。我设法用.pack()函数实现了这一点,但它不在理想的位置。我在internet上搜索,但找不到使用.place()的解决方案,只有.pack()和.grid()。 而不是从上到下的线条 from tkinter import * from tkinter import ttk App = Tk() ttk.Separator(App, orient=VERTICAL).place(x=27

我想使用
.place()
函数将分隔符从窗口顶部到底部放置在特定位置。当我这样做时,分隔符只是一个小点。我设法用
.pack()
函数实现了这一点,但它不在理想的位置。我在internet上搜索,但找不到使用
.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()
调用:

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()
从tkinter导入*
从tkinter导入ttk
App=Tk()
sep=ttk.分隔符(应用,方向=垂直)
sep.place(x=50,y=0,height=App.winfo_height())
App.bind(“”,lambda e:sep.place(x=50,y=0,height=App.winfo_height())
App.mainloop()

希望对你有帮助

我知道的最简单的解决方案是在
place()上指定
高度=
以像素为单位。
调用:

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()
从tkinter导入*
从tkinter导入ttk
App=Tk()
sep=ttk.分隔符(应用,方向=垂直)
sep.place(x=50,y=0,height=App.winfo_height())
App.bind(“”,lambda e:sep.place(x=50,y=0,height=App.winfo_height())
App.mainloop()

希望对你有帮助

那帮了大忙,谢谢。我不知道我可以在
.place()
中指定高度。它有一个问题-当窗口更改高度时,它不会更改分隔符的高度。但是
relheight=1.0
而不是
height=
解决了这个问题。@furas在这里,所以你可以使用px表达式为什么不直接使用
relheight=1.0
呢?如果你需要的话,你可以编写精确的像素表达式(从底部开始的100px等)。你可能会的。那帮了大忙,谢谢。我不知道我可以在
.place()
中指定高度。它有一个问题-当窗口更改高度时,它不会更改分隔符的高度。但是
relheight=1.0
而不是
height=
解决了这个问题。@furas在这里,所以你可以使用px表达式为什么不直接使用
relheight=1.0
呢?如果你需要的话,你可以编写精确的像素表达式(从底部开始的100px等)。您可能会。
place(…,relheight=1.0)
place(…,relheight=1.0)