FRAMES IN TKINTER
In this tutorial, we are going to learn about frames in Tkinter and how we can use them in complex formations containing multiple widgets inside it.
What are Frames in Tkinter?
Frames in tkinter ares used to organize and contain other widgets inside it. There are also used to give padding between the elements while being the base source itself. To declare a frame, we use the following syntax:
frame_tk = Frame( window, features )
Frame features and properties are:
1 | bd | Displays the border width |
2 | bg | Declares the background color of the frame |
3 | cursor | You can use the cursor as different shapes on the screen as circle, dot etc. |
4 | height | Declares the height of the frame. |
5 | highlightbackground | Shows the color of the background in focus |
6 | highlightcolor | Shows the color of text in focus. |
7 | highlightthickness | Planks the thickness of the highlight border |
8 | relief | Sets the border type. The default is FLAT |
9 | width | Sets the frame width. |
Creating Your First Frame
from tkinter import * screen = Tk() screen.geometry('200x200') #top frame frame_up = Frame(screen) frame_up.pack() #Bottom Frame frame_down = Frame(screen) frame_down.pack() #Green Button green = Button(frame_up, text="green", fg="green") green.pack(side=LEFT) #Blue Button blue = Button(frame_up, text="blue", fg="blue") blue.pack(side=LEFT) #Red Button red = Button(frame_down, text="red", fg="red") red.pack(side=BOTTOM) screen.mainloop()
Output will be:
References have been used from here