Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Create Multiple frames with Grid manager using Tkinter
Next article icon

Prerequisite:Tkinter

It is very easy to create a basic frame using Tkinter, this article focuses on how another frame can be created within it. To create a basic frame the name of the parent window is given as the first parameter to the frame() function. Therefore, to add another frame within this frame, just the name of the first frame needs to given to the second frame as the parent window.

Optional values such as frame padding are give relative to the parent window. We can add multiple frames in this fashion using the same approach, by making the previous frame the parent of the current frame.

Approach:

  • Create Normal Tkinter Window
  • Create first frame normally
  • Create second frame
  • Take the first window as its parent window
  • Execute code

frame() is an inbuilt Tkinter method which helps realize our required functionality.

Syntax:frame(master)

Parameter:

  • master: parent window
  • highlightcolor: To set the color of the focus highlight when widget has to be focused.
  • bd: to set the border width in pixels.
  • bg: to set the normal background color.
  • cursor: to set the cursor used.
  • width: to set the width of the widget.
  • height: to set the height of the widget.

Program:

Python3
# Import Modulefromtkinterimport*# Create Tkinter Objectroot=Tk()# Set Geometryroot.geometry("400x400")# Frame 1frame1=Frame(root,bg="black",width=500,height=300)frame1.pack()# Frame 2frame2=Frame(frame1,bg="white",width=100,height=100)frame2.pack(pady=20,padx=20)# Execute Tkinterroot.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