Python 3.4 Tkinter - 无法为PanedWindow中的帧提供大小

时间:2016-03-26 20:56:53

标签: python-3.x tkinter size

from tkinter import *
from tkinter import ttk

_root = Tk()

_F_Cassa = PanedWindow(_root, orient = HORIZONTAL)
_F_Cassa.pack(fill = BOTH, expand = True )

_F_Right = Frame(_F_Cassa)
_F_Left = Frame(_F_Cassa)


_F_Cassa.add(_F_Left)
_F_Cassa.add(_F_Right)

_L_NomeS = Button(_F_Left, text = "Sinistra")
_L_NomeS.grid(row = 0, column = 0)


_L_NomeD = Button(_F_Right, text = "Destra")
_L_NomeD.grid(row = 0, column = 0)


_root.mainloop()

我正在尝试构建一个包含PanedWindow窗口小部件的应用程序,该窗口小部件包含2个框架(左侧和右侧),然后填充“标准”窗口小部件,如按钮,标签等...问题是我得到了这个结果:

enter image description here

但我想要的是这样的:

enter image description here

我尝试为帧添加宽度和高度,但它没有用。

所以一切都很清楚:我没有使用ttk模块中的小部件,只是正常的tk。

1 个答案:

答案 0 :(得分:1)

实际上,您无法直接更改Frame实例的维度,因为这两个框架都是PaneWindow子窗口小部件。

要解决您的问题,您需要调查paneconfig()这样的方法:

_F_Cassa.paneconfig(_F_Left, width = 120, height = 400, sticky = E+W+S+N)
_F_Cassa.paneconfig(_F_Right, width =  200, height = 400, sticky = E+W+S+N)

完整程序:

from tkinter import *

_root = Tk()
_root.title("BEGUERADJ PaneWindow")

_F_Cassa = PanedWindow(_root, orient = HORIZONTAL)
_F_Cassa.pack(fill = BOTH, expand = True )
"""
Every column and row has a "weight" grid option associated with it, 
which tells it how much it should grow if there is extra room in the 
_F_Cassa to fill. By default, the weight of each column or row is 0, 
meaning don't expand to fill space.
"""
_F_Cassa.grid_rowconfigure(0, weight = 1)
_F_Cassa.grid_columnconfigure(0, weight = 1)

# I set background colors just to highlight the results
_F_Right = Frame(_F_Cassa, bg = "blue")
_F_Left = Frame(_F_Cassa, bg = "yellow")    

_F_Cassa.add(_F_Left)
_F_Cassa.add(_F_Right)

_F_Right.grid(row = 0, column = 1)
_F_Left.grid(row = 0, column = 0)

_L_NomeS = Button(_F_Left, text = "Sinistra")
_L_NomeS.grid(row = 0, column = 0)


_L_NomeD = Button(_F_Right, text = "Destra")
_L_NomeD.grid(row = 0, column = 0)   

# Resize frame widgets:
_F_Cassa.paneconfig(_F_Left, width = 120, height = 400, sticky = E+W+S+N)
_F_Cassa.paneconfig(_F_Right, width =  200, height = 400, sticky = E+W+S+N)


_root.mainloop()

演示

enter image description here