About the Frame Tkinter widget

A frame is simply a container for other widgets. Each frame has its own positioning manager. Thus, the layout of the widgets in each frame is independent. Frame widgets are good tools for making your application modular. You can group a consistent set of widgets by placing them in a frame. Better yet, you can create your own frame class by inheriting it from Frame, and making your own interface for that frame. This is a good technique for hiding the details of the interactions of a group's widgets.


widget_frame = Frame (master, option, ...)
  1. master: represents the parent window.
  2. options: list of the most commonly used options for this widget. These options can be used as key-value pairs separated by commas.

List of options of a Frame widget

  1. bg: Frame widget background color
  2. bd: size of the borders around the Frame.
  3. cursor: allows you to customize the pattern of the mouse cursor when hovering.
  4. height: defines the vertical dimension of the Frame.
  5. highlightbackground: sets the color of the highlightbackground of the Frame object.
  6. highlightcolor:
  7. relief: with the default relief = FLAT, the checkbox does not stand out from its background. You can set this option to any other style.
  8. width: defines the width of the frame


from tkinter import *

# Creation of the main window
master = Tk ()
master.geometry ("400x200")

# Creation of a green background frame
frm = Frame (master, bg = 'green')

# Frame location
frm.place (x = 50, y = 20, width = 200, height = 75)

# Creation of a button within the frame
b = Button (frm, text = "a button", bg = 'red', fg = 'white')
b.place (x = 10, y = 10, width = 100, height = 30)

The body widget may be very critical for the procedure of grouping and organizing different widgets in a in some way friendly manner. it works like a box, that is chargeable for arranging the position of different widgets. It makes use of rectangular regions within the display screen to organize the layout and to provide padding of these widgets. A body can also be used as a basis class to implement complex widgets. Syntax here is the easy syntax to create this widget − w = frame ( master, choice, ... ) Parameters grasp − This represents the determine window. alternatives − right here is the list of most generally used alternatives for this widget. those options can be used as key-cost pairs separated by means of commas. Sr.No. choice & Description cursor: in case you set this selection to a cursor name (arrow, dot and so on.), the mouse cursor will trade to that pattern while it's miles over the checkbutton. highlightbackground: colour of the point of interest spotlight while the frame does now not have consciousness. The default width of a checkbutton is determined via the size of the displayed photograph or text. you can set this option to some of characters and the checkbutton will always have room for that many characters.
Younes Derfoufi

Leave a Reply