Python Tkinter Frame Widget
In this post, you will learn about the Tkinter Frame widget.
Tkinter is a standard cross-platform package for creating graphical user interfaces (GUIs). It is also called the Tk interface. It is an original GUI library for Tcl (Tool Command Language). Tkinter comes pre-installed with Python. The greatest strength of Tkinter is its simplicity. Tkinter is rich in widgets, like radiobutton, checkbutton, menu, frame, canvas, and much more.
The frame widget is a container for other widgets. It is like a master that arranges the position for other widgets, which will be handled by a geometry manager. This widget has limited options and no methods other than standard widget options. However, we can bind mouse and keyboard events to callbacks.
Syntax of Frame Widget
w = frame( master, options)
These are the possible options of Frame widget -
Options | Descriptions |
bg | To represent the normal background color displayed behind the label and indicator. |
bd | To represent the size of the border around the indicator, and the default value is 2 pixels. |
cursor | To show a cursor when the mouse pointer is moved over the widget. |
height | The vertical dimension of the new frame. |
highlightcolor | To represent the color of the focus highlight when the frame has the focus. |
highlightthickness | To represent the thickness of the focus highlight. |
highlightbackground | To represent the focus highlight when the frame does not have focus. |
padx | To leave space to the left and right of the widget. |
pady | To leave space to the top and the button of the widget. |
relief | The type of the border of the frame. It's default value is set to FLAT. |
width | The horizontal dimension of the new frame. |
Python Tkinter frame widget
The given Python program adds a frame widget to the window and sets the background color.
from tkinter import *
root = Tk()
f = Frame(root, width=320, height=150)
xf = Frame(f, relief=GROOVE, borderwidth=5, bg="cyan", padx = 10, pady = 10)
Label(xf, text="Python Tkinter Frame Widget Example ").pack(pady=10)
Button(xf, text="Not Done", state=DISABLED).pack(side=LEFT, padx=5,
pady=5)
Button(xf, text="Done", command=root.quit).pack(side=RIGHT,
padx=5, pady=5)
xf.place(relx=0.01, rely=0.125, anchor=NW)
f.pack()
mainloop()
The above code returns the following output -
Python Tkinter frame widget
Here is other example of Python tkinter frame widget.
from tkinter import *
root = Tk()
root.geometry("300x150")
frame = Frame(root)
frame.pack()
bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )
onbutton = Button(frame, text="On", fg="red", font="30")
onbutton.pack( side = LEFT)
offbutton = Button(frame, text="Off", fg="brown", font="30")
offbutton.pack( side = LEFT )
pausebutton = Button(frame, text="Pause", fg="blue", font="30")
pausebutton.pack( side = LEFT )
playbutton = Button(bottomframe, text="Play", fg="green", font="30")
playbutton.pack( side = BOTTOM)
playbutton.pack(padx=20,pady=20)
root.mainloop()
Output of the above code:
Related Articles
Python Tkinter Tutorial with ExamplesPython Tkinter Combobox Event Binding
Python Tkinter Geometry Managers
Python3 Tkinter Messagebox
Python Tkinter Frame Widget
Python Tkinter Scale Widget
Entry Field Validation in Tkinter Python
Python Tkinter Text Widget
Python Tkinter Checkbutton Widget
Python 3 Tkinter Menu Bar
Add background image in Python Tkinter
OpenCV histogram equalization color
Color histogram Python OpenCV
Histogram of grayscale image python
High pass filter OpenCV python
Python OpenCV ColorMap
OpenCV Gaussian blur Python
Python OpenCV Overview and Examples