A frame is rectangular region on the screen. The frame widget is mainly used as a geometry master for other widgets, or to provide padding between other widgets.
Syantax:
w = frame( master, options)
Example:
from Tkinter import *
master = Tk()
Label(text="one").pack()
separator = Frame(height=2, bd=1, relief=SUNKEN)
separator.pack(fill=X, padx=5, pady=5)
Label(text="two").pack()
mainloop()
Frame Options: Following are commonly used Option can be used with this widget :-
bg: This option used to represent the normal background color displayed behind the label and indicator.
bd: This option used to represent the size of the border around the indicator and the default value is 2 pixels.
cursor: By using this option, the mouse cursor will change to that pattern when it is over the frame.
height: The vertical dimension of the new frame.
highlightcolor: This option used to represent the color of the focus highlight when the frame has the focus.
highlightthickness: This option used to represent the color of the focus highlight when the frame does not have focus.
highlightbackground: This option used to represent the thickness of the focus highlight..
relief: The type of the border of the frame. It’s default value is set to FLAT.
width: This option used to represents the width of the frame.
Creating Multiple Frames In Tkinter Window
We can also create the multiple frames in single window;
Example:
from tkinter import * root = Tk()
root.geometry("300x150")
w = Label(root, text ='GeeksForGeeks', font = "50")
w.pack()
frame = Frame(root)
frame.pack()
bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )
b1_button = Button(frame, text ="Geeks1", fg ="red")
b1_button.pack( side = LEFT)
b2_button = Button(frame, text ="Geeks2", fg ="brown")
b2_button.pack( side = LEFT )
b3_button = Button(frame, text ="Geeks3", fg ="blue")
b3_button.pack( side = LEFT )
b4_button = Button(bottomframe, text ="Geeks4", fg ="green")
b4_button.pack( side = BOTTOM)
b5_button = Button(bottomframe, text ="Geeks5", fg ="green")
b5_button.pack( side = BOTTOM)
b6_button = Button(bottomframe, text ="Geeks6", fg ="green")
b6_button.pack( side = BOTTOM)
root.mainloop()
Tkinter Lables
The Label widget is a standard Tkinter widget used to display a text or image on the screen.
Syntax
w = Label ( master, option, ... )
Parameters
master − This represents the parent window.
options − Here is the list of most commonly used options for this widget. These options can be used as key-value pairs separated by commas.
Example
from Tkinter import *
master = Tk()
w = Label(master, text="Hello, world!")
w.pack()
mainloop()
How to use textvariable() with Lables:
v = StringVar()
Label(master, textvariable=v).pack()
v.set("New Text!")
LabelFrame
The LabelFrame can be used when you want to group a number of related widgets, such as a number of radiobuttons.
Example:
from Tkinter import *
master = Tk()
group = LabelFrame(master, text="Group", padx=5, pady=5)
group.pack(padx=10, pady=10)
w = Entry(group)
w.pack()
mainloop()