import tkinter as tk root = tk.Tk() root.title("Frame Example") frame = tk.Frame(root, padx=10, pady=10) frame.pack() label = tk.Label(frame, text="This is a frame with a label") label.pack() root.mainloop()
import tkinter as tk root = tk.Tk() root.title("Frame Example") frame = tk.Frame(root) frame.pack() button1 = tk.Button(frame, text="Button 1") button1.pack(side="left", padx=10) button2 = tk.Button(frame, text="Button 2") button2.pack(side="right", padx=10) root.mainloop()This code example creates a Frame with two Button widgets. The Frame is added to the root window using the pack() method. The two Button widgets are added to the Frame using the pack() method, but this time with the side="left" and side="right" arguments. This argument positions the widgets to the left and right of the Frame. The padx argument adds padding to the horizontal axis. The package library used in this example is Tkinter.