-1

私の場合、これはコードを実行したときに表示されるエラーです。

TypeError: __init__() missing 1 required positional argument: 'Screen'

通常、これは簡単に修正できますが、奇妙な理由で問題を解決できないようです。私は以前は完全に優れたコードを持っていましたが、いじり始めたので、私のコードはエラーだらけになりました。古いコードに戻りますが、エラーを整理すると、この新しいコードは古いコードよりもはるかに優れたものになります。彼らが言うように、「一度にすべてを一歩ずつ進めなければなりません」。

コード(このような大きなコードを提供して申し訳ありませんが、私の場合、完全なコードが必要かどうかはわかりません):

import pygame
import sys
from pygame.locals import *

white = (255,255,255)
black = (0,0,0)
objs = []
MAIN_BUTTON = 1


class Pane():

    def __init__(self, textToDisplay, coordinates, screen):
        self.textToDisplay = textToDisplay
        self.coordinates = coordinates
        self.screen = screen

    def drawPane(self):
        self.screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
        pygame.draw.rect(self.screen, (black), self.coordinates, 2)
        pygame.display.update()


class Screen():

    #constants/array(?) outlining the x,y boundaries of each of x10 panes

    #Remember to change co-ordinate values
    #number of panes
    NoOfPanes = 0
    Panes = []

    def __init__(self, Screen):
        pygame.init()
        pygame.display.set_caption('Box Test')

        self.font = pygame.font.SysFont('Arial', 25)
        Screen = pygame.display.set_mode((1000,600), 0, 32)
        self.screen = Screen #I'm guessing the error of my code is somewhere around here, however I thought that I had overcome the situation. Evidently I haven't "sigh"!
        self.screen.fill((white))

        pygame.display.update()

    def addPane(self, textToDisplay):
        #right now it is displaying them all change so that it checks how many
        #panes are on through (numberOfPanes = 0) 10 is limit display no more
        #than ten.
        paneLocs = [(175, 75, 200, 100), 
                    (0, 0, 200, 100), 
                    (600, 400, 200, 100), 
                    (175, 75, 200, 100), 
                    (175, 75, 200, 100), 
                    (175, 75, 200, 100), 
                    (175, 75, 200, 100), 
                    (175, 75, 200, 100), 
                    (175, 75, 200, 100), 
                    (175, 75, 200, 100)
                    ]

        if self.NoOfPanes > 10:
            print("Limit Reached")            
        else:
            #self.Panes[self.NoOfPanes] = Pane(textToDisplay, paneLocs[self.NoOfPanes])
            #self.Panes[self.NoOfPanes].drawPane()

            myPane = Pane(textToDisplay, paneLocs[self.NoOfPanes])
            myPane.drawPane()

            self.NoOfPanes = self.NoOfPanes + 1
            pygame.display.update()


    def mousePosition(self):
        global clickPos
        global releasePos
        for event in pygame.event.get():
            if event.type == MAIN_BUTTON:
                self.Pos = pygame.mouse.get_pos()
                return MAIN_BUTTON
            else:
                return False


if __name__ == '__main__':

    myScreen = Screen()
    myScreen.addPane("1")
    myScreen.addPane("2")
    myScreen.addPane("3")
    myScreen.addPane("4")

    while True:
        ev = pygame.event.get()
        for event in ev:
            if event.type == pygame.MOUSEBUTTONUP:
                posx,posy = pygame.mouse.get_pos()
                if (posx >= 175 and posx <= 375) and (posy >= 75 and posy <= 175):
                    print("BOB") #Printing bob was for test purposes.

        for event in pygame.event.get():        
            if event.type == pygame.QUIT:
                pygame.quit(); sys.exit();

お時間と労力をいただきありがとうございます。

4

1 に答える 1