简体   繁体   中英

TypeError: 'module' object is not callable in Python 3

I'm using PyGame to make my own 'game engine' in Python 3.7. I want to make a class that uses the pygame.rect() function but when I run it it gives me this error or a similar one every time.

main.py (./pyseed/)

# Imports
import pygame

pygame.init()

# class
class Shape:
    def __init__(self, width, height, color):
        self.width = width
        self.height = height
        self.color = color
        self.SHAPE = pygame.rect(self, width, height, color)

# RunApp() function
def runApp(width, height):
    screen = pygame.display.set_mode((width, height))
    done = False

    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

        pygame.display.flip()

testing.py ( import main will change to import pyseed.main )

# PySeed Testing Zone
import main as pyseed

myShape = pyseed.Shape(90, 90, (0, 100, 255))

pyseed.runApp(400, 300)

Thank you for any help.

My New Code:

main.py

# Made by DeBeast591
# Enjoy!

# Imports
import pygame

# Getting PyGame ready...
pygame.init()
print("Welcome to PySeed!\nMade By DeBeast591\nEnjoy!")

def setUp(width, height):
    global screen
    screen = pygame.display.set_mode((width, height))

# class
class Shape:
    def __init__(self, x, y, width, height, color):
        global screen
        self.width = width
        self.height = height
        self.x = x
        self.y = y
        self.color = color
        self.SHAPE = pygame.draw.rect(screen, self.color,pygame.Rect(self.x, self.y, self.width, self.height))

# RunApp() function
def runApp():
    global screen
    done = False

    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

        pygame.display.flip()

testing.py

# PySeed Testing Zone
import main as pyseed

pyseed.setUp(400, 300)

myShape = pyseed.Shape(30, 30, 90, 90, (0, 100, 255))

pyseed.runApp()

Thank you for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM