We now have a youtube channel. Subscribe!

Python Tkinter Frame Widget

Hello dear readers! welcome back to another section of our tutorial on Python. In this tutorial post, we are going to be discussing about the Python Tkinter Frame Widget.

The Tkinter Frame widget is very key for the process of grouping, as well as arranging other widgets in a very friendly way. It works like a container, which is responsible for organizing the position of other widgets.

It makes use of rectangular areas in the screen to organize the layout and to provide padding of these widgets. A frame widget can also be used as a foundation class for the implementation of complex widgets.


The following below is the syntax for create this widget -

w = Frame ( master, option, ... )

Parameter Details

  • master - This represents the parent window.
  • options - Following below is the list of commonly used options for this widget. These options can be used as key-value pairs that are separated by commas.

Sr.No.Option & Description
The normal background color displayed behind the label and indicator.
The size of the border around the indicator. Default is 2 pixels.
If you set this option to a cursor name (arrow, dot etc.), the mouse cursor will change to that pattern when it is over the checkbutton.
The vertical dimension of the new frame.
Color of the focus highlight when the frame does not have focus.
Color shown in the focus highlight when the frame has the focus.
Thickness of the focus highlight.
With the default value, relief=FLAT, the checkbutton does not stand out from its background. You may set this option to any of the other styles
The default width of a checkbutton is determined by the size of the displayed image or text. You can set this option to a number of characters and the checkbutton will always have room for that many characters.


Following is a simple example -

from Tkinter import *

root = Tk()
frame = Frame(root)

bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )

redbutton = Button(frame, text="Red", fg="red")
redbutton.pack( side = LEFT)

greenbutton = Button(frame, text="Brown", fg="brown")
greenbutton.pack( side = LEFT )

bluebutton = Button(frame, text="Blue", fg="blue")
bluebutton.pack( side = LEFT )

blackbutton = Button(bottomframe, text="Black", fg="black")
blackbutton.pack( side = BOTTOM)



When the above code is executed, it will produce the following result -

Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the Python Tkinter Label Widget.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain