个性化阅读
专注于IT技术分析

Python Tkinter中的PanedWindow小部件用法

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

语法:PanedWindow(master, ** options)参数:master:父窗口小部件或main Tk()对象选项:在配置方法中或直接在构造函数中传递

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()

输出如下:

Python Tkinter中的PanedWindow小部件1

代码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()

输出如下:

Python Tkinter中的PanedWindow小部件2

首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。


赞(0)
未经允许不得转载:srcmini » Python Tkinter中的PanedWindow小部件用法

评论 抢沙发

评论前必须登录!