[Tutor] method could be a function warning
Phil
phillor9 at gmail.com
Wed Dec 22 19:59:37 EST 2021
I've been in the habit of mixing methods and functions within the GUI
class and to get the functions to work I've had to prefix the call to
the function with .self and add self as a function argument. The
function dummy in the following code is an an example of this.
It makes more sense to me, and I think it's correct, to define and call
the functions outside the GUI class as I've done with my_function below.
Also, I'm thinking that the GUI class should be in a file of it's own
because the total number of lines of code exceeds 500 thus making
scrolling tedious.
I ask because I'm in the process of tidying up a Conway's Game of Life
project that I wrote 3 years ago.
import tkinter as tk
class Root(tk.Tk):
def __init__(self):
super().__init__()
self.title('test')
self.geometry('300x300')
self.frame = tk.Frame()
self.dummy()
def dummy(self):
print('hello')
def my_function():
print('my function')
my_function()
if __name__ == '__main__':
root = Root()
root.mainloop()
--
Regards,
Phil
More information about the Tutor
mailing list