
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Using A Frame Class in Tkinter
Tkinter Frame widget is very useful for grouping multiple widgets in a frame. It includes all the functions and properties that applies to the parent window.
To create a Frame widget, we can instantiate an object of the Frame class. Once we define the Frame widget in the window, we can directly pick any widget and place it into the frame.
Example
In this example, we've created a Frame widget and defined some widgets in it.
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x250") def on_click(): label["text"]="Hello "+ str(entry.get()) # Create a Frame widget frame=Frame(win, width=400, height=300) # Add a label in the frame widget label=Label(frame, text="Enter your name", font=('Calibri 13')) label.pack(pady=10) # Add an Entry widget entry=Entry(frame, width=25) entry.pack() # Create a button ttk.Button(frame, text="Click Me", command=on_click).pack() frame.pack() win.mainloop()
Output
Running the above code will display a window that will contain an Entry widget, a label widget, and a button in a frame.
Type your name in the given text field and click the button to display the message on the screen.
Advertisements