Example 2: Frame Widget

 import tkinter as tk


# Create the main application window

root = tk.Tk()

root.title("Nested Frames Example")

root.geometry("400x300")


# Create the main frame

main_frame = tk.Frame(root, bg="lightgrey", bd=2, relief=tk.SUNKEN)

main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)


# Create the top frame inside the main frame

top_frame = tk.Frame(main_frame, bg="lightblue", bd=2, relief=tk.RAISED)

top_frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)


# Create the bottom frame inside the main frame

bottom_frame = tk.Frame(main_frame, bg="lightgreen", bd=2, relief=tk.RAISED)

bottom_frame.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)


# Add widgets to the top frame

label1 = tk.Label(top_frame, text="Top Frame Label", bg="lightblue")

label1.pack(pady=10)


entry1 = tk.Entry(top_frame)

entry1.pack(pady=10)


# Add widgets to the bottom frame

label2 = tk.Label(bottom_frame, text="Bottom Frame Label", bg="lightgreen")

label2.pack(pady=10)


button1 = tk.Button(bottom_frame, text="Submit")

button1.pack(pady=10)


# Run the application

root.mainloop()




Comments