I see two methods for using the tkinter
module with python classes.
- the first method uses the
super()
method. - the second method does not.
So the example code looks like this:
import tkinter as tk
class MyClass(tk.Tk):
''' class using super '''
def __init__(self):
super().__init__()
self.title('class using super')
self.mainloop()
return
class MyOhterClass:
''' class that does not use super '''
def __init__(self):
self.win = tk.Tk()
self.win.title('class NOT using super')
self.win.mainloop()
return
# main guard idiom
if __name__=='__main__':
app_1 = MyClass()
app_2 = MyOhterClass()
Both of the classes work.
It looks like i can achieve exactly the same with both (as far as i can tell). The only difference being self
compared to self.win
for creation of the actual tkinter window.
But which of the two class methods is preferable (if any) ?