Python Tkinter Frame

Created with Sketch.

Python Tkinter Frame

Python Tkinter Frame widget is used to organize the group of widgets. It acts like a container which can be used to hold the other widgets. The rectangular areas of the screen are used to organize the widgets to the python application.

The syntax to use the Frame widget is given below.

Syntax

  1. w = Frame(parent,  options)

A list of possible options is given below.

SNOptionDescription
1bdIt represents the border width.
2bgThe background color of the widget.
3cursorThe mouse pointer is changed to the cursor type set to different values like an arrow, dot, etc.
4heightThe height of the frame.
5highlightbackgroundThe color of the background color when it is under focus.
6highlightcolorThe text color when the widget is under focus.
7highlightthicknessIt specifies the thickness around the border when the widget is under the focus.
8reliefIt specifies the type of the border. The default value if FLAT.
9widthIt represents the width of the widget.

Example

  1. from tkinter import *
  2. top = Tk()
  3. top.geometry(“140×100”)
  4. frame = Frame(top)
  5. frame.pack()
  6. leftframe = Frame(top)
  7. leftframe.pack(side = LEFT)
  8. rightframe = Frame(top)
  9. rightframe.pack(side = RIGHT)
  10. btn1 = Button(frame, text=“Submit”, fg=“red”,activebackground = “red”)
  11. btn1.pack(side = LEFT)
  12. btn2 = Button(frame, text=“Remove”, fg=“brown”, activebackground = “brown”)
  13. btn2.pack(side = RIGHT)
  14. btn3 = Button(rightframe, text=“Add”, fg=“blue”, activebackground = “blue”)
  15. btn3.pack(side = LEFT)
  16. btn4 = Button(leftframe, text=“Modify”, fg=“black”, activebackground = “white”)
  17. btn4.pack(side = RIGHT)
  18. top.mainloop()

Output:

Python Tkinter Frame

 

Leave a Reply

Your email address will not be published. Required fields are marked *