In this TKinter Tutorial we are going to learn creating TKinter Window Class, before this we have learned that how you can create window in tkinter, in this lesson we are going to use Object Oriented Programming for creating window.
OK now this is the complete code for this lesson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import tkinter as tk class Window(tk.Tk): def __init__(self): super(Window, self).__init__() self.title("Tkinter OOP Window") self.minsize(400,350) self.wm_iconbitmap("myicon.ico") window = Window() window.mainloop() |
In the above code we have created main class for our Window, this class extends from tkinter.Tk.
“__init__” is a reserved method in python classes. It is called as a constructor in object oriented programming. This method is called when an object is created from a class and it allows the class to initialize the attributes of the class.
The super() function is used to give access to methods and properties of a parent class. And the super() function makes class inheritance more manageable.
The word ‘self’ is used to represent the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python.
Run the complete code and this is the result.
![TKinter Tutorial - TKinter Window Class](https://geekscoders.com/wp-content/uploads/2021/02/tkinter-tutorial-tkinter-window-class.jpg)