Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python Tkinter - Frameless window
Next article icon

Prerequisites: Tkinter

Tkinter can support the creation of more than one widget in the same frame. Not just this it also supports a mechanism to align them relative to each other. One of the easiest ways of aligning the different widgets in the Tkinter is through grid manager. Apart from aligning various widgets, the grid manager can also be used for aligning the numerous frames. 

In this article, we will be discussing the approach of aligning multiple frames with Grid Manager.

For this first the frames needs to be defined, and then they need to be aligned using grid().

Syntax:

frame1=LabelFrame(app, text="#Text you want to give in frame")

frame1.grid(row=#Row value, column=#Column value)

Function Used

  • LabelFrame() is used to create a frame
  • grid() is used to apply grid manager to the widgets created

Approach

  • Import module
  • Create a GUI app using tkinter
  • Give a title to the app.(optional)
  • Now, create the first frame, i.e., frame1
  • Display the frame1 in grid manager by specifying row and column values.
  • Further, create a widget you wish to get display in the frame1.
  • Display the widget you made in previous step.
  • For creating more frames, repeat from steps 4 to 7. Repeat these steps n number of times for creating n number of frames. Don't forget to change the row value and column value for every frame. You can change the row value and column value of the frames according to the given image.
  • Finally, make the loop for displaying the GUI app on the screen.

Program:

Python
# Import the library tkinterfromtkinterimport*# Create a GUI appapp=Tk()# Give a title to your appapp.title("Vinayak App")# Constructing the first frame, frame1frame1=LabelFrame(app,text="Fruit",bg="green",fg="white",padx=15,pady=15)# Displaying the frame1 in row 0 and column 0frame1.grid(row=0,column=0)# Constructing the button b1 in frame1b1=Button(frame1,text="Apple")# Displaying the button b1b1.pack()# Constructing the second frame, frame2frame2=LabelFrame(app,text="Vegetable",bg="yellow",padx=15,pady=15)# Displaying the frame2 in row 0 and column 1frame2.grid(row=0,column=1)# Constructing the button in frame2b2=Button(frame2,text="Tomato")# Displaying the button b2b2.pack()# Make the loop for displaying appapp.mainloop()

Output:


Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp