[英]Tkinter: PanedWindow not stretching within Frames
I am trying to create two "pages" in the main window with Frames and PanedWindows.我正在尝试使用 Frames 和 PanedWindows 在主窗口中创建两个“页面”。 The "Main" class uses a PanedWindow which is inherited by the two pages.
“Main”类使用由两个页面继承的 PanedWindow。 They are then being initialized as Frames which consist of either PanedWindow(s) or Frame(s).
然后它们被初始化为由 PanedWindow(s) 或 Frame(s) 组成的框架。 The Problem is that they don't stretch .
问题是它们不会拉伸。 Neither of them have a sash despite that it has been added ( sashwidth=50 ).
尽管已经添加了腰带( sashwidth=50 ),但它们都没有腰带。
I have checked in stackoverflow, but didn't found anything relevant.我已经检查了 stackoverflow,但没有发现任何相关的内容。 Can someone explain to me why this is happening?
有人可以向我解释为什么会这样吗?
import tkinter as tk
from tkinter import ttk
class Main(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "Program")
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
container = tk.PanedWindow(self, bg='bisque',orient=tk.HORIZONTAL, relief='groove', borderwidth=2, sashwidth=3)
container.grid(row=0, column=0)
self.frames = {}
main_page = MainPage(container, self)
self.frames[0] = main_page
main_page.grid(row=0, column=0, sticky="nsew")
plotting_page = PlottingPage(container, self)
self.frames[1] = plotting_page
plotting_page.grid(row=0, column=1, sticky="nsew")
class MainPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
# Paned Windows
top_pane = tk.PanedWindow(self, orient=tk.HORIZONTAL, relief='groove', borderwidth=2, sashwidth=3)
top_pane.grid(column=0, row=1, sticky="nsew", columnspan=4)
top_pane.rowconfigure(0, weight=1)
top_pane.columnconfigure(0, weight=1)
top_pane.rowconfigure(1, weight=1)
top_pane.columnconfigure(1, weight=1)
bottom_pane = tk.PanedWindow(self, orient=tk.VERTICAL, relief='groove', borderwidth=2, sashwidth=50)
bottom_pane.grid(column=0, row=2, sticky="nsew", columnspan=2)
bottom_pane.rowconfigure(0, weight=1)
bottom_pane.columnconfigure(0, weight=1)
bottom_pane.rowconfigure(1, weight=1)
bottom_pane.columnconfigure(1, weight=1)
# Frames
top_frame = ttk.LabelFrame(self, text="Top frame")
bottom_frame = ttk.LabelFrame(self, text="Bottom frame")
# Layout of frames
top_frame.grid(row=1, column=0, sticky="nsew")
bottom_frame.grid(row=2, column=0, sticky="ew")
top_frame.columnconfigure(0, weight=1)
top_frame.columnconfigure(1, weight=1)
top_frame.rowconfigure(0, weight=1)
top_frame.rowconfigure(1, weight=1)
top_pane.add(top_frame, stretch="always")
bottom_frame.columnconfigure(0, weight=1)
bottom_frame.columnconfigure(1, weight=1)
bottom_frame.rowconfigure(0, weight=1)
bottom_frame.rowconfigure(1, weight=1)
bottom_pane.add(bottom_frame, stretch="always")
top = tk.Label(top_frame, text="top pane")
top.grid(column=1, row=0, sticky="nsew")
bottom = tk.Label(bottom_frame, text="bottom pane")
bottom.grid(column=1, row=0, sticky="nsew")
class PlottingPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
# Paned Windows
right_pane = tk.PanedWindow(self, orient=tk.HORIZONTAL, relief='groove', borderwidth=2, sashwidth=3)
right_pane.grid(column=2, row=1, sticky="nsew", columnspan=4)
right_pane.rowconfigure(0, weight=1)
right_pane.columnconfigure(0, weight=1)
right_pane.rowconfigure(1, weight=1)
right_pane.columnconfigure(1, weight=1)
# Frames
right_frame = ttk.LabelFrame(self, text="Right frame")
# Layout of frames
right_frame.grid(row=1, column=2, sticky="nsew")
right_frame.columnconfigure(0, weight=1)
right_frame.columnconfigure(1, weight=1)
right_frame.rowconfigure(0, weight=1)
right_frame.rowconfigure(1, weight=1)
right_pane.add(right_frame, stretch="always")
# Widgets
right = tk.Label(right_frame, text="right pane")
right.grid(column=1, row=1, sticky="nsew")
def main():
app = Main()
app.mainloop()
if __name__ == '__main__':
main()
The issue was, that i hadn't configured all columns & rows.问题是,我没有配置所有的列和行。 You should use columnconfigure, rowconfigure for EVERY row & column inside that "span".
您应该对“跨度”内的每一行和列使用 columnconfigure、rowconfigure。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.