在我而言,這是我的錯誤,當我運行代碼:我怎麼能理清缺少必需的位置參數
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();
。
您是否使用VCS? (例如Git或Mercurial,Bazaar也可以通過) –
您能提供完整的追溯嗎?很難弄清楚最後一部分例外情況。追蹤的其餘部分應該告訴你究竟是哪條線路導致了這個問題。 – Blckknght
你的事件循環被分成兩個循環。人們可以吃其他人期待的事件。它應該是一個循環。 – ninMonkey