TypeError:'module'对象在Python 3中不可调用

问题描述 投票:0回答:1

我正在使用PyGame在Python 3.7中制作自己的“游戏引擎”。我想创建一个使用pygame.rect()函数的类,但是当我运行它时,每次都会给我这个错误或类似的错误。

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将更改为import pyseed.main

# PySeed Testing Zone
import main as pyseed

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

pyseed.runApp(400, 300)

谢谢您的帮助。

python pygame python-3.7
1个回答
0
投票

我的新代码:

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()

谢谢您的帮助。

© www.soinside.com 2019 - 2024. All rights reserved.