Thursday, September 3, 2020

Python Tkinter Frame Widget



Hello dear readers! welcome back to another section of my 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.

Syntax

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
1
bg
The normal background color displayed behind the label and indicator.
2
bd
The size of the border around the indicator. Default is 2 pixels.
3
cursor
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.
4
height
The vertical dimension of the new frame.
5
highlightbackground
Color of the focus highlight when the frame does not have focus.
6
highlightcolor
Color shown in the focus highlight when the frame has the focus.
7
highlightthickness
Thickness of the focus highlight.
8
relief
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
9
width
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.


Example

Following is a simple example -

from Tkinter import *

root = Tk()
frame = Frame(root)
frame.pack()

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)

root.mainloop()

Output

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 my 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.
Share:

0 comments:

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.