I am attempting to refactor a pygame moduel “test.py” into a class. I expect it to crate the a (500,500) pygame screen and exit properly. Before refactoring it works perfectly. There is a function called ‘run_game()’ that contains the while loop and the exit procedure.
When the class is executed I get ‘TypeError: test.run_game() missing 1 required positional argument :’self’
import pygame
import sys
class test:
def init (self):
self.screen = pygame.display.set_mode((500,500))
def run_game(self):
while True:
self.define_screen()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if name == ‘main‘:
cl = test
cl.run_game()
David Underwood is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.