Tkinter Create widget inside Frame
When you create a Frame, you pass back the Frame object. Assuming that this object is A, when you create a Widget control in this frame later, this object A is the parent container of the Widget control in the Frame. The following is an explanation of creating a function button object within a Frame.
A = Frame(root, ...) # Pass back Frame object A
btn = Button(A, ...) # Frame object A is the parent container of btn function button
Tkinter Create widget inside Frame Example#1
Create two frames, while building three function buttons inside the upper Frame frameUpper, and the lower Frame is frameLower.
from tkinter import *
root = Tk()
root.title("apidemos.com")
frameUpper = Frame(root,bg="lightyellow") # create frameUpper
frameUpper.pack()
btnRed = Button(frameUpper,text="Red",fg="red")
btnRed.pack(side=LEFT,padx=5,pady=5)
btnGreen = Button(frameUpper,text="Green",fg="green")
btnGreen.pack(side=LEFT,padx=5,pady=5)
btnBlue = Button(frameUpper,text="Blue",fg="blue")
btnBlue.pack(side=LEFT,padx=5,pady=5)
frameLower = Frame(root,bg="lightblue") # create frameLower
frameLower.pack()
btnPurple = Button(frameLower,text="Purple",fg="purple")
btnPurple.pack(side=LEFT,padx=5,pady=5)
root.mainloop()
Output: