How to use PanedWindow in Python.

The PanedWindow is a widget in the Tkinter library that is used to create a container which can be divided into multiple sub-windows. Sub-windows can be added horizontally or vertically, and the size of the sub-windows can be adjusted by dragging the separator bar.

Below is a simple example demonstrating how to use a PanedWindow.

from tkinter import *

root = Tk()

# 创建一个PanedWindow对象
paned_window = PanedWindow(root, orient=HORIZONTAL)
paned_window.pack(fill=BOTH, expand=True)

# 创建两个子窗口
frame1 = Frame(paned_window, width=100, height=200, bg='red')
frame2 = Frame(paned_window, width=200, height=200, bg='blue')

# 将子窗口添加到PanedWindow中
paned_window.add(frame1)
paned_window.add(frame2)

root.mainloop()

In this example, we first created a PanedWindow object and specified its orientation as horizontal. Then, we created two child windows frame1 and frame2, and added them to the PanedWindow using the add() method.

Finally, use the pack() method to place the PanedWindow in the Tkinter window, and utilize the fill and expand parameters to fill and expand it to the entire window.

You can run this code to see the result of PanedWindow. You can try dragging the separator to adjust the size of the sub-windows.

bannerAds