Tkinter Frame

Tkinter Frame widget is used to organize other widgets present in Python GUI. It outlines the frame or structure for a Tkinter window of a fixed size. For better organization of widgets, create Frames within Frames.

Syntax:

The Parameter master represents the parent window and options can be used as key-value pairs separated by commas.

Options of Tkinker Frame:

height: This option shows the vertical dimension of the new frame.

bd: This option shows the size of the border around the indicator. By default it’s 2 pixels.

bg: This option shows the normal background color behind the label.

highlightthickness: This option shows thickness of the focus highlight.

highlightcolor: This shows the color shown in the focus highlight.

relief: This shows the the default value, relief=FLAT.

cursor: This option sets as a cursor name , the mouse cursor will change to the other pattern.

width: This option shows the normal width of the frame.

highlightbackground: This options shows the color of the background color when it is under focus.

Example:
from tkinter import *

appWindow = Tk()
appWindow.title("Window Title-Tutorialsart.com")

appWindow.geometry('350x200')

frame1 = Frame(appWindow)
frame1.pack()


Right_Frame = Frame(appWindow)
Right_Frame.pack(side=RIGHT)

Left_Frame = Frame(appWindow)
Left_Frame.pack(side=LEFT)

label1 = Label(frame1, text="PYTHON TKINTER FRAMES",bg="orange")
label1.pack()

button1 = Button(Right_Frame, text="BUTTON 1")
button1.pack(padx=2, pady=2)
button2 = Button(Left_Frame, text = "BUTTON 2")
button2.pack(padx=2, pady=2)


appWindow.mainloop()
Output:
06 Tkinter Frame

Comments are closed.