當我運行此代碼時,出現錯誤「ValueError:size requires(int width,int height)」。在pygame中向屏幕添加文本時遇到問題
display_width = 800
display_height = 600
welcomeScreen = pygame.display.set_mode((display_width, display_height))
red = (255, 0, 0)
white = (255, 255, 255)
welcomeScreen.fill(white, rect = None, special_flags = 0)
welcomeMessageBackground = pygame.draw.rect(welcomeScreen, red, [200, 100, 400, 75])
welcomeFont = pygame.font.Font(None, 50)
welcomeMessage = welcomeFont.render('Welcome! Click a button to get started.', True, white)
pygame.Surface.blit(pygame.Surface(display_width, display_height), welcomeMessageBackground, area = None, special_flags = 0)
pygame.display.update()
導致問題的行是
pygame.Surface.blit(pygame.Surface(display_width, display_height), welcomeMessageBackground, area = None, special_flags = 0)
我已經試過了值800和600,同樣的錯誤替換的變量。我想要的是welcomeMessage中的文本顯示在rect welcomeMessageBackground上。任何幫助表示讚賞!