所以在我决定问这个问题之前,我做了一些研究,看看我的问题是什么,并遇到了这个问题:Code Only Produces Black Screen In Pygame Window然而,这并不是很有帮助,因为我没有遇到与这个相同的问题人。我肯定知道我的 PyGame 并没有过时或类似的东西,因为我的代码的先前版本正在运行。
每次我运行代码时,都会出现黑屏。
这是我的代码(抱歉有点长):
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)
def drawPane(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 drawPane1(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 drawPane2(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 drawPane3(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 drawPane4(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 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()
self.font = pygame.font.SysFont('Arial', 25)
pygame.display.set_caption('Box Test')
self.screen = pygame.display.set_mode((1000,600), 0, 32)
self.screen.fill((white))
pygame.display.update()
numberOfPanes = 0
self.NoOfPanes = numberOfPanes
def addPane(self, textToDisplay):
myPane = Pane()
myPane.drawPane(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.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()
print(posx)
print(posy)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
因此,我基本上是在尝试从内部显示窗格(现在是一个)**class Pane()**
,**class Screen()**
但是就像我之前说的那样,当我运行代码时出现黑屏。但由于某种原因,鼠标坐标跟踪器仍然有效。任何帮助是极大的赞赏。