Frame in tkinter in python by R4R Team

- Frame() Tkinter widget is very important for the process of grouping and organizing other widgets. It works like a container, and content in one Frame do not affects the other Frame content.
-It uses rectangular areas in the screen to organize the layout and to provide padding of these widgets. A frame can also be used as a foundation class to implement complex widgets.

Syntax-

Frame(window,option,...)


program-

from tkinter import *
#create a window screen
win=Tk()
win.geometry("400x350")

#create a two Frame
f1=Frame(win,height=150,width=400,bg="red")
f1.pack(side=TOP)

f2=Frame(win,height=250,width=400,bg="blue")
f2.pack(side=BOTTOM)

#create a First Label
l1=Label(f1,text="Text in First Frame",bg="red",font=('',20,'bold'))
l1.place(x=30,y=30)
l1.config(bg="Red",fg="white")

#create a second label
l2=Label(f2,text="Text in Second Frame",bg="blue",font=('',15,'bold'))
l2.place(x=100,y=100)
l2.config(bg="blue",fg="white")

#hold the screen
win.mainloop()


output-



-In this program, we initially create a window screen by win=Tk() and hold the screen by win.mainloop() in the last.
-Then we create a two Frame, f1 and f2 are the object of that frames, then we put different labels in different Frames so that each Frame treated as single Unique entity.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!