- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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 a Tk class in Python 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.
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()
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.
- Related Articles
- Removing the TK icon on a Tkinter window
- What are the advantages in using a Python class?
- Determine if a class is a subclass of a second class in Python
- How to put a border around a Frame in Python Tkinter?
- Difference between import tkinter as tk and from tkinter import
- Create a queue using LinkedList class in Java
- What are static methods in a Python class?
- Class Inheritance in Python
- self in Python class
- Difference between title() and wm_title() methods in Tkinter class
- Draw a circle in using Tkinter Python
- How do we check if a class is a subclass of the given super class in Python?
- How to serialize a Python class?
- Increment a Month using the Calendar Class in Java
- Decrement a Month using the Calendar Class in Java