Python 为什么我的代码示例会导致黑屏?

Python 为什么我的代码示例会导致黑屏?,python,python-2.7,pygame,easygui,Python,Python 2.7,Pygame,Easygui,我的代码示例只会导致黑屏,我不知道为什么。我用Python2.7、pygame和easygui在Windows7上运行这个 import pygame, easygui, io, time BLACK = ( 0, 0, 0) WHITE = ( 255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) PINK = (255, 0, 255) PURPLE = (130, 0, 130)

我的代码示例只会导致黑屏,我不知道为什么。我用Python2.7、pygame和easygui在Windows7上运行这个

import pygame, easygui, io, time
BLACK   = (   0,   0,   0)
WHITE   = ( 255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
PINK = (255, 0, 255)
PURPLE = (130, 0, 130)

programMode = 0

class TextPrint:
    def __init__(self):
        self.reset()
        self.font = pygame.font.Font(None, 20)

    def printline(self, screen, textString):
        textBitmap = self.font.render(textString, True, WHITE)
        screen.blit(textBitmap, [self.x, self.y])
        self.y += self.line_height

    def printDebugLine(self, screen, textString):
        textBitmap = self.font.render(textString, True, RED)
        screen.blit(textBitmap, [self.debugX, self.debugY])
        self.debugY += self.debugLineHeight

    def reset(self):
        self.x = 600
        self.debugX = 600
        self.y = 400
        self.debugY = 400
        self.line_height = 15
        self.debugLineHeight = 13

    def indent(self):
        self.x += 10

    def unindent(self):
        self.x -= 10

pygame.init()


size = [950, 750]
screen = pygame.display.set_mode(size)

pygame.display.set_caption("Robot Joystick Control Version 2.0")

done = False

clock = pygame.time.Clock()

pygame.joystick.init()

textPrint = TextPrint()

myfont = pygame.font.SysFont("monospace", 25)

camImg = pygame.image.load('C:\Users\Evan Develop\Desktop\Python Code     Examples\Zalophus/camImg.png')
camImgx = 425
camImgy = 20

rovImg = pygame.image.load('C:\Users\Evan Develop\Desktop\Python Code Examples\Zalophus/rovImg.png')
rovImgx = 425
rovImgy = 385

hG = pygame.image.load('C:\Users\Evan Develop\Desktop\Python Code Examples\Zalophus/hG.png')
hGx = 10
hGy = 500
while done==False:
    # EVENT PROCESSING STEP
    for event in pygame.event.get(): 
        if event.type == pygame.QUIT: 
            done=True 

    JOYBUTTONUP JOYHATMOTION
        if event.type == pygame.JOYBUTTONDOWN:
            textPrint.printline(screen, "Joystick button pressed.")

    screen.fill(BLACK)
    textPrint.reset()

    joystick_count = pygame.joystick.get_count()

    textPrint.printline(screen, "Number of joysticks: {}".format(joystick_count) )
    textPrint.indent()

    if (joystick_count == 0):
        textPrint.printline(screen, "No joysticks connected...")
    if (joystick_count == 1):
        i = 0
        joystick = pygame.joystick.Joystick(i)
        joystick.init()

        textPrint.printDebugLine(screen, "Joystick {}".format(i) )
        textPrint.indent()
        name = joystick.get_name()
        textPrint.printDebugLine(screen, "Joystick name: {}".format(name) )


        axes = joystick.get_numaxes()
        textPrint.printDebugLine(screen, "Number of axes: {}".format(axes) )
        textPrint.indent()

        for i in range( axes ):
            axis = (joystick.get_axis( i ) * -100)
            textPrint.printDebugLine(screen, "Axis {} value: {:>6.3f}".format(i, axis) )
        textPrint.indent()


        buttons = joystick.get_numbuttons()
        textPrint.printline(screen, "Number of buttons: {}".format(buttons) )
        textPrint.indent()
        almostExplode1 = False
        almostExplode2 = False
        for i in range( buttons ):
            button = joystick.get_button( i )
            textPrint.printline(screen, "Button {:>2} value: {}".format(i,button) )
            if (i == 8 and button == 1):
                almostExplode1 = True
            if (i == 9 and button == 1):
                almostExplode2 = True
            if (almostExplode1 == True and almostExplode2 == True):
                print ("\n \n OH NOOOOOO!!! Joystick EXPLODED!!!!\n\n" * 20)
                done = True
                break
        textPrint.unindent()

        hats = joystick.get_numhats()
        textPrint.printline(screen, "   Number of hats: {}".format(hats) )
        textPrint.indent()

        for i in range( hats ):
            hat = joystick.get_hat( i )
            textPrint.printline(screen, "Hat {} value: {}".format(i, str(hat)) )

        textPrint.indent()


        numOfAxes = axes
        directionByte = 0
    # Axes used for driving, drawing, and direction byte.
        yAxis = int(joystick.get_axis(1) * -100)
        xAxis = int(joystick.get_axis(0) * -100)
        zAxis = int(joystick.get_axis(2) * -100)
        wAxis = int(joystick.get_axis(3) * -100)
        if (yAxis > 10):
            directionByte = 1
        elif (yAxis < -10):
            directionByte = 2
        if (xAxis > 10 and (xAxis > yAxis and xAxis > -yAxis)):
            directionByte = 3
        elif (xAxis < -10 and (xAxis < yAxis and xAxis < -yAxis)):
            directionByte = 4
        if (wAxis > 10 and (wAxis > yAxis and wAxis > -yAxis and wAxis > xAxis and wAxis > -xAxis)):
            directionByte = 5
        elif (wAxis < -10 and (wAxis < yAxis and wAxis < -yAxis and wAxis < xAxis and wAxis < -xAxis)):
            directionByte = 6

        yAxisDot = int(joystick.get_axis(1) * 250 + 600)
        xAxisDot = int(joystick.get_axis(0) * 250 + 350)
        zAxisDot = int(joystick.get_axis(2) * 250 + 350)
        wAxisDot = int(joystick.get_axis(3) * 250 + 600)

        pygame.draw.circle(screen, BLUE, [xAxisDot, 600], 15, 0)
        pygame.draw.circle(screen, RED, [350, yAxisDot], 15, 0)
        pygame.draw.circle(screen, GREEN, [zAxisDot, 600], 15, 0)
        pygame.draw.circle(screen, WHITE, [350, wAxisDot], 15, 0)


label = myfont.render("Cam Feed #1", 1, (255,255,0))
screen.blit(label, (450, 25))
label = myfont.render("Cam Feed #2", 1, (255,255,0))
screen.blit(label, (450, 390))


pygame.display.flip()


clock.tick(25)
pygame.quit ()
导入pygame、easygui、io、时间
黑色=(0,0,0)
白色=(255,255,255)
红色=(255,0,0)
绿色=(0,255,0)
蓝色=(0,0255)
粉红色=(255,0255)
紫色=(130,0130)
编程模式=0
类文本打印:
定义初始化(自):
self.reset()
self.font=pygame.font.font(无,20)
def打印行(自身、屏幕、文本字符串):
textBitmap=self.font.render(textString,True,白色)
blit(文本位图,[self.x,self.y])
self.y+=self.line\u高度
def printDebugLine(自身、屏幕、文本字符串):
textBitmap=self.font.render(textString,True,红色)
blit(文本位图,[self.debugX,self.debugY])
self.debugY+=self.debugLineHeight
def重置(自):
self.x=600
self.debugX=600
self.y=400
self.debugY=400
自连线高度=15
self.debugLineHeight=13
def缩进(自):
自身x+=10
定义未登录(自我):
自身x-=10
pygame.init()
大小=[950750]
screen=pygame.display.set_模式(大小)
pygame.display.set_标题(“机器人操纵杆控制2.0版”)
完成=错误
clock=pygame.time.clock()
pygame.maggage.init()
textPrint=textPrint()
myfont=pygame.font.SysFont(“monospace”,25)
caimg=pygame.image.load('C:\Users\Evan Develop\Desktop\Python代码示例\Zalophus/caimg.png')
camImgx=425
卡米基=20
rovImg=pygame.image.load('C:\Users\Evan Develop\Desktop\Python代码示例\Zalophus/rovImg.png')
rovImgx=425
rovImgy=385
hG=pygame.image.load('C:\Users\Evan Develop\Desktop\Python Code Examples\Zalophus/hG.png')
hGx=10
hGy=500
完成时==False:
#事件处理步骤
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
完成=正确
JoyButtonUpJoyHatMotion
如果event.type==pygame.JOYBUTTONDOWN:
打印行(屏幕,“操纵杆按钮按下”)
屏幕填充(黑色)
textPrint.reset()
操纵杆计数=pygame.mogage.get\u计数()
打印行(屏幕,“操纵杆数量:{}”。格式(操纵杆计数))
textPrint.indent()
如果(操纵杆计数==0):
textPrint.printline(屏幕,“未连接操纵手柄…”)
如果(操纵杆计数==1):
i=0
操纵杆=pygame.操纵杆.操纵杆(i)
init()文件
printDebugLine(屏幕,“操纵杆{}”.format(i))
textPrint.indent()
name=操纵杆。get_name()
printDebugLine(屏幕,“操纵杆名称:{}”。格式(名称))
轴=操纵杆。获取最大值()
printDebugLine(屏幕,“轴数:{}”。格式(轴))
textPrint.indent()
对于范围内的i(轴):
轴=(操纵杆。获取_轴(i)*-100)
printDebugLine(屏幕,“轴{}值:{:>6.3f}”。格式(i,轴))
textPrint.indent()
按钮=操纵杆。获取按钮()
打印行(屏幕,“按钮数:{}”。格式(按钮))
textPrint.indent()
almostExplode1=假
almostExplode2=错误
对于范围内的i(按钮):
按钮=操纵杆。获取按钮(i)
打印行(屏幕,“按钮{:>2}值:{}”。格式(i,按钮))
如果(i==8,按钮==1):
almostExplode1=真
如果(i==9,按钮==1):
almostExplode2=真
如果(almostExplode1==True和almostExplode2==True):
打印(“\n\n OH NOOOOOO!!!操纵杆爆炸!!!!\n\n”*20)
完成=正确
打破
textPrint.unindent()
hats=操纵杆。获取数值()
打印行(屏幕,“帽子数量:{}”。格式(帽子))
textPrint.indent()
对于范围内的i(hats):
hat=操纵杆。获取(i)
打印行(屏幕,“Hat{}值:{}”。格式(i,str(Hat)))
textPrint.indent()
numOfAxes=轴
方向字节=0
#用于驱动、绘图和方向字节的轴。
yAxis=int(操纵杆获取轴(1)*-100)
xAxis=int(操纵杆获取_轴(0)*-100)
zAxis=int(操纵杆获取轴(2)*-100)
wAxis=int(操纵杆获取轴(3)*-100)
如果(yAxis>10):
方向字节=1
elif(yAxis<-10):
方向字节=2
如果(xAxis>10和(xAxis>yAxis和xAxis>-yAxis)):
方向字节=3
elif(xAxis<-10和(xAxis10和(wAxis>yAxis和wAxis>-yAxis和wAxis>xAxis和wAxis>-xAxis)):
方向字节=5
elif(wAxis<-10和(wAxis
此部分

label = myfont.render("Cam Feed #1", 1, (255,255,0))
screen.blit(label, (450, 25))
label = myfont.render("Cam Feed #2", 1, (255,255,0))
screen.blit(label, (450, 390))

pygame.display.flip()

clock.tick(25)

需要成为while循环的一部分。

您需要调用
pygame.display.flip()
while
循环中的某个地方,在您翻转显示之前,您所显示/绘制的所有内容都不会出现。您知道吗