代码在Pycharm中工作正常,但在IDLE中却给出错误?

时间:2019-12-23 23:42:35

标签: python pygame pycharm python-idle

此代码在我的pycharm中起作用,但在IDLE中不起作用,它们都运行3.7。当我在IDLE中运行它时,控制台中收到"<rect(0, 0, 750, 750)>"垃圾邮件。如果我拖动窗口周围,它将获取我设置的背景颜色。

import pygame
import random

blue = (135, 206, 250)
black = ( 0, 0, 0)
white = ( 255, 255, 255)

gravity = 1 # speed
FPS = 60 #FPS
width = 750
height = 750
snowSize = 8
snowNum = 50

varHeight = height
snowColour = white
bgColour = blue


# Intialize the pygame
pygame.init()

# create the screen
screen = pygame.display.set_mode((750, 750))


#Font
myfont = pygame.font.SysFont('Comic Sans MS', 25)


#Title and Icon
pygame.display.set_caption("Christmas Card")

#player
playerImg = pygame.image.load('C:/Users/Owner/Desktop/tammy program/untitled-2.png')
playerX = 300
playerY = 350

#player2
playerImg2 = pygame.image.load('C:/Users/Owner/Desktop/tammy program/tree.png')
player2X = 5
player2Y = 5

snowFlake = []
for q in range(snowNum):
    x = random.randrange(0,width)
    y = random.randrange(0,varHeight)
    snowFlake.append([x,y])
clock = pygame.time.Clock



def player():
    screen.blit(playerImg, (playerX, playerY))

def player2():
    screen.blit(playerImg2, (player2X, player2Y))

def greeting():
    screen.blit(textsurface, (300, 0))

# Game Loop
running = True
while running:
    # Screen Color
    screen.fill((125, 205, 255))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    textsurface = myfont.render('Merry Christmas', False, (0, 0, 0))
    greeting()
    player()
    player2()

    for i in snowFlake:
        i[1] += gravity

    pygame.draw.circle(screen, snowColour, i, snowSize)

    if i[1] > varHeight:
        i[1] = random.randrange(-50, -5)
        i[0] = random.randrange(width)

    pygame.display.flip()

    pygame.display.update()

0 个答案:

没有答案