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