This is an unofficial mirror of Tkinter reference documentation (based on Python 2.7 and Tk 8.5) created by the late John Shipman.
It was last updated in 2013 and is unmaintained.[More info]
Tkinter 8.5 reference: a GUI for Python | ![]() |
A frame is basically just a container for other widgets.
Your application's root window is basically a frame.
Each frame has its own grid layout, so thegridding of widgets within each frame works independently.
Frame widgets are a valuable tool in making your application modular. You can group a set of related widgets into a compound widget by putting them into a frame. Better yet, you can declare a new class that inherits fromFrame
, adding your own interface to it. This is a good way to hide the details of interactions within a group of related widgets from the outside world.
To create a new frame widget in a root window or frame named
:parent
w
= Frame(parent
,option
, ...)
The constructor returns the newFrame
widget. Options:
Table 19. Frame
widget options
bg orbackground | The frame's background color. SeeSection 5.3, “Colors”. |
bd orborderwidth | Width of the frame's border. The default is 0 (no border). For permitted values, seeSection 5.1, “Dimensions”. |
cursor | The cursor used when the mouse is within the frame widget; seeSection 5.8, “Cursors”. |
height | The verticaldimension of the new frame. This will be ignored unless you also call.grid_propagate(0) on the frame; seeSection 4.2, “Other grid management methods”. |
highlightbackground | Color of the focus highlight when the frame does not have focus. SeeSection 53, “Focus: routing keyboard input”. |
highlightcolor | Color shown in the focus highlight when the frame has thefocus. |
highlightthickness | Thickness of thefocus highlight. |
padx | Normally, aFrame fits tightly around its contents. To add pixels of horizontal space inside the frame, setpadx= . |
pady | Used to add vertical space inside a frame. Seepadx above. |
relief | The default relief for a frame istk.FLAT , which means the frame will blend in with its surroundings. To put a border around a frame, set itsborderwidth to a positive value and set its relief to one of the standard relief types; seeSection 5.6, “Relief styles”. |
takefocus | Normally, frame widgets are not visited by input focus (seeSection 53, “Focus: routing keyboard input” for an overview of this topic). However, you can settakefocus=1 if you want the frame to receive keyboard input. To handle such input, you will need to create bindings for keyboard events; seeSection 54, “Events” for more on events and bindings. |
width | The horizontal dimension of the new frame. SeeSection 5.1, “Dimensions”. This value be ignored unless you also call.grid_propagate(0) on the frame; seeSection 4.2, “Other grid management methods”. |