So I was following your tkinter tuts and I'm getting really confused, like you said in the video, I know about classes and what they do but they're insanely confusing when I have no idea what im typing when following a video of yours,. import tkinter as tk
LARGE_FONT = ("Verdana", 12)
class SeaOfBTC(tk.Tk): def __init__(self, *args, **kwargs): print(self) #I thought maybe this would give me an answer, all it gave me was "." tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) #why is self here?
You must be logged in to post. Please login or register an account.
You should check out the OOP section of the intermediate series, starting here: https://pythonprogramming.net/object-oriented-programming-introduction-intermediate-python-tutorial/. It covers OOP, including what self is, much more in-depth.
-Harrison 7 years ago
You must be logged in to post. Please login or register an account.
Thank you, I started watching that, I somehow got off track.
-Ghosting12 7 years ago
You must be logged in to post. Please login or register an account.
I just watched about 3 videos, before I got completely lost, I think I understand self to an extent, (probably due to the lack of not being interested / not knowing in pygame so I was confused) and I still don't get how you just call self in the function I commented by, frame = StartPage(container, self) #and here ?? what is self??
-Ghosting12 7 years ago
Last edited 7 years ago
You must be logged in to post. Please login or register an account.
self is the object. It's there because it's not a function, it's a method, and that method is part of the overall class. self is that class/object.
With self, you can reference attributes from other methods (the things that look like functions, but aren't), or even variables outside of other methods, but yet still defined in the class...etc.
It's just the thing that is passed in every method.
OOP is just plain confusing at first. The best way to get used to it is to just force yourself to use it sometimes, and tinker with things.
Also, it might also just be the case that my explanations aren't the best for you in this case. For me to really "get" OOP, I had to visit quite a few sources.
-Harrison 7 years ago
You must be logged in to post. Please login or register an account.
I *think* I get self and how you accesses your variables (attributes) and functions (method) doing self.var, self.func, but what I don't get is when you pass in self by itself, what is it doing?
-Ghosting12 7 years ago
You must be logged in to post. Please login or register an account.
Just like when you pass a parameter to a function or method, it allows you to access it. You're passing self for the same reason, so you can access it in the method.
-Harrison 7 years ago
You must be logged in to post. Please login or register an account.