📜  Python| Tkinter 中的 PanedWindow 小部件

📅  最后修改于: 2022-05-13 01:54:39.913000             🧑  作者: Mango

Python| Tkinter 中的 PanedWindow 小部件

Tkinter 支持各种小部件,使 GUI 越来越有吸引力和功能。 PanedWindow小部件是一个几何管理器小部件,它可以包含一个或多个子小部件窗格。用户可以通过使用鼠标移动分隔线框来调整子小部件的大小。

PanedWindow 可用于实现常见的 2 窗格或 3 窗格,但可以使用多个窗格。

代码 #1:只有两个窗格的 PanedWindow

# Importing everything from tkinter module
from tkinter import * from tkinter import ttk
  
# main tkinter window
root = Tk()
  
# panedwindow object
pw = PanedWindow(orient ='vertical')
  
# Button widget
top = ttk.Button(pw, text ="Click Me !\nI'm a Button")
top.pack(side = TOP)
  
# This will add button widget to the panedwindow
pw.add(top)
  
# Checkbutton Widget
bot = Checkbutton(pw, text ="Choose Me !")
bot.pack(side = TOP)
  
# This will add Checkbutton to panedwindow
pw.add(bot)
  
# expand is used so that widgets can expand
# fill is used to let widgets adjust itself
# according to the size of main window
pw.pack(fill = BOTH, expand = True)
  
# This method is used to show sash
pw.configure(sashrelief = RAISED)
  
# Infinite loop can be destroyed by
# keyboard or mouse interrupt
mainloop()

输出:
代码 #2:具有多个窗格的 PanedWindow

# Importing everything from tkinter module
from tkinter import * from tkinter import ttk
  
# main tkinter window
root = Tk()
  
# panedwindow object
pw = PanedWindow(orient ='vertical')
  
# Button widget
top = ttk.Button(pw, text ="Click Me !\nI'm a Button")
top.pack(side = TOP)
  
# This will add button widget to the panedwindow
pw.add(top)
  
# Checkbutton Widget
bot = Checkbutton(pw, text ="Choose Me !")
bot.pack(side = TOP)
  
# This will add Checkbutton to panedwindow
pw.add(bot)
  
# adding Label widget
label = Label(pw, text ="I'm a Label")
label.pack(side = TOP)
  
pw.add(label)
  
# Tkinter string variable
string = StringVar()
  
# Entry widget with some styling in fonts
entry = Entry(pw, textvariable = string, font =('arial', 15, 'bold'))
entry.pack()
  
# Focus force is used to focus on particular
# widget that means widget is already selected for operations
entry.focus_force()
  
pw.add(entry)
  
# expand is used so that widgets can expand
# fill is used to let widgets adjust itself
# according to the size of main window
pw.pack(fill = BOTH, expand = True)
  
# This method is used to show sash
pw.configure(sashrelief = RAISED)
  
# Infinite loop can be destroyed by
# keyboard or mouse interrupt
mainloop()

输出: