Skip to content
Advertisement

Defining a classmethod outside of a class in Python [closed]

I am making a game with Pygame where there are going to be many different screens. I am making a class called Screen that will have custom screens made for you. I need each screen to have different events and triggers though, so I can’t just define one function in the class. I need separate functions for each screen which would mean that I need to define functions out side of the class definition for each screen. I don’t know if this is possible but it would be good to know. I have not gotten too far in yet but here is the code:

JavaScript

Advertisement

Answer

I need each screen to have different events and triggers though

So you are searching for Inheritance. Read about Inheritance and Polymorphism in Python Use Screen as a base class. Derive different classes from Screen, where you can implement different behavior:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement