2 つの異なるペインを呼び出すと、両方が同じ画面に表示されない理由がわかりません。それはどちらかです。誰かがなぜこれが当てはまるのかを教えて助けてください。また、問題を修正して両方のペインを画面に表示できるようにする方法を教えてください。
完全なコードは次のとおりです。
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):
self.Screen = pygame.display.set_mode((1000,600), 0, 32)
self.font = pygame.font.SysFont('Arial', 25)
self.Screen.fill((white))
pygame.display.update()
def drawPane(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (75, 135))
pygame.draw.rect(self.Screen, (black), (0, 100, 200, 100), 2)
def drawPane1(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (200, 300, 200, 100), 2)
def drawPane2(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (400, 500, 200, 100), 2)
def drawPane3(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (600, 75, 200, 100), 2)
def drawPane4(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (800, 75, 200, 100), 2)
def drawPane5(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (175, 75, 200, 100), 2)
def drawPane6(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (175, 75, 200, 100), 2)
def drawPane7(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (175, 75, 200, 100), 2)
def drawPane8(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (175, 75, 200, 100), 2)
def drawPane9(self, textToDisplay):
self.Screen.blit(self.font.render(textToDisplay, True, (black)), (250, 115))
pygame.draw.rect(self.Screen, (black), (175, 75, 200, 100), 2)
class Screen():
def __init__(self):
pygame.init()
pygame.display.set_caption('Box Test')
numberOfPanes = 0
self.NoOfPanes = numberOfPanes
def addPane(self, textToDisplay):
myPane = Pane()
myPane.drawPane(textToDisplay)
def addPane1(self, textToDisplay):
myPane = Pane()
myPane.drawPane1(textToDisplay)
def addPane2(self, textToDisplay):
myPane = Pane()
myPane.drawPane2(textToDisplay)
def addPane3(self, textToDisplay):
myPane = Pane()
myPane.drawPane3(textToDisplay)
def addPane4(self, textToDisplay):
myPane = Pane()
myPane.drawPane4(textToDisplay)
def addPane5(self, textToDisplay):
myPane = Pane()
myPane.drawPane5(textToDisplay)
def addPane6(self, textToDisplay):
myPane = Pane()
myPane.drawPane6(textToDisplay)
def addPane7(self, textToDisplay):
myPane = Pane()
myPane.drawPane7(textToDisplay)
def addPane8(self, textToDisplay):
myPane = Pane()
myPane.drawPane8(textToDisplay)
def addPane9(self, textToDisplay):
myPane = Pane()
myPane.drawPane9(textToDisplay)
def clearScreen(self):
self.screen = pygame.display.set_mode((600,400), 0, 32)
self.screen.fill((white))
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__':
Pan3 = Screen()
Pan3.addPane("hello")
Pan3.addPane1("b")
Pan3.mousePosition()
pygame.display.update()
while True:
ev = pygame.event.get()
for event in ev:
if event.type == pygame.MOUSEBUTTONUP:
posx,posy = pygame.mouse.get_pos()
if (posx >=175 or posx <=375) and (posy >=75 or posy <= 175):
print("bob")
else:
print("error")
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
どんな助けでも大歓迎です。ありがとうございました。