을 정렬 할 수 있습니다 방법 :내가 코드를 실행할 때이 내가 오류 내 경우에는 누락 필요한 위치 인수
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
클래스의 생성자처럼 보이는
VCS를 아직 사용하고 있습니까? (예 : Git 또는 Mercurial, Bazaar도 통행 가능) –
전체 추적을 제공 할 수 있습니까? 예외의 마지막 부분 만 예외가 어디에서 발생하는지 파악하기는 어렵습니다. 나머지 추적 표시는 문제의 원인이되는 행을 정확히 알려야합니다. – Blckknght
이벤트 루프는 두 개의 루프로 분할됩니다. 다른 사람이 기대하는 이벤트를 먹을 수 있습니다. 그것은 루프를위한 하나 여야합니다. – ninMonkey