2013-10-24 1 views
0

을 정렬 할 수 있습니다 방법 :내가 코드를 실행할 때이 내가 오류 내 경우에는 누락 필요한 위치 인수

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

을 .

def __init__(self, Screen): <-- the 'Screen' here is causing the issue. 

당신의 오류 메시지가 말하는 것 같다 무엇 : 그것은 Screen 클래스의 생성자처럼 보이는

+0

VCS를 아직 사용하고 있습니까? (예 : Git 또는 Mercurial, Bazaar도 통행 가능) –

+0

전체 추적을 제공 할 수 있습니까? 예외의 마지막 부분 만 예외가 어디에서 발생하는지 파악하기는 어렵습니다. 나머지 추적 표시는 문제의 원인이되는 행을 정확히 알려야합니다. – Blckknght

+0

이벤트 루프는 두 개의 루프로 분할됩니다. 다른 사람이 기대하는 이벤트를 먹을 수 있습니다. 그것은 루프를위한 하나 여야합니다. – ninMonkey

답변

3

는 불량 매개 변수가 있습니다. 'Screen'매개 변수를 제거하십시오. 그렇지 않으면 Python은 그것이 위치 매개 변수라고 생각합니다.

다음과 같이 : 파이썬 스타일 가이드 (Google PEP-8)를 통해 읽는 것이 좋습니다. 변수에 대한 클래스 용으로 예약 된 대/소문자를 사용하는 것으로 보이며 합리적인 기간 동안 Python으로 작성된 사람에게는 코드를 읽기 쉽게 만듭니다.

+0

매우 늦은 답변을 드려 죄송합니다. 그러나 여전히이 오류 메시지가 나타납니다. myScreen.addPane ("1") 파일 "C : \ Users \ Burak \ Desktop \ boxtrial.py", 줄 66, addPane myPane = 창 (textToDisplay, paneLocs [self.NoOfPanes]) TypeError : __init __() missing 1 필수 위치 인수 : 'screen'> – PythonNovice

+0

@PythonNovice : 창 생성자에 'screen'이라는 세 번째 인자가 필요합니다. 그래서'myPane = Pane (textToDisplay, paneLocs [self.NoOfPanes])'는'myPane = Pane (textToDisplay, paneLocs [self.NoOfPanes], screen)'이어야합니다.'screen'은 아마도'Screen' 타입 일 것입니다. 'myPane = Pane (textToDisplay, paneLocs [self.NoOfPanes], Screen())'을 사용하면 Pane 생성자 자체에 대한 호출에서 인스턴스를 생성 할 수 있습니다. – scorpiodawg

관련 문제