- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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
Inheriting from Frame or not in a Tkinter application
In the Object-Oriented Programming Paradigm, Inheritance is used for acquiring the properties of the base class and using them in a derived class. Considering the case for a Tkinter application, we can inherit all the properties of a frame defined in a base class such as background color, foreground color, font properties, etc., into a derived class or a frame.
In order to support Inheritance, we have to define a class that contains some basic properties of a frame such as height, width, bg, fg, font, etc.
Example
# Import Tkinter Library from tkinter import * # Create an instance of Tkinter frame win= Tk() # Set the size of the application window win.geometry("700x350") # Create a class to define the frame class NewFrame(Frame): def __init__(self, win): super().__init__() self["height"] = 200 self["width"] = 200 self["bd"] = 10 self["relief"] = RAISED self["bg"] = "#aa11bb" # Create Frame object frame_a= NewFrame(win) frame_b= NewFrame(win) frame_a.grid(row=0, column=0) frame_b.grid(row=0, column=1) win.mainloop()
Output
Running the above code will display a window containing two frames having the same properties of its frame defined in a class.
- Related Articles
- How to set padding of all widgets inside a window or frame in Tkinter?
- How to set the min and max height or width of a Frame in Tkinter?
- How to make a system tray application in Tkinter?
- Tkinter scrollbar for frame
- Creating Tkinter full-screen application
- How to check whether a data frame exists or not in R?
- How to clear out a frame in the Tkinter?
- How to set the tab order in a Tkinter application?
- How to display a tkinter application in fullscreen on macOS?
- Embedding a matplotlib animation into a tkinter frame
- How to center a Tkinter widget in a sticky frame?
- How to stop Tkinter Frame from shrinking to fit its contents?
- Using a Frame class in a Tk class in Python tkinter
- Good example of functional testing a Python Tkinter application
- How to bundle a Python Tkinter application including dependencies?

Advertisements