pygame的学习以及python的巩固(窗口尺寸的显示)

来源:互联网 发布:照片白边框软件 编辑:程序博客网 时间:2024/06/05 15:11

这次学习的地址是:http://eyehere.net/2011/python-pygame-novice-professional-3/

这一篇主要讲了全屏显示的切换和改变窗口尺寸等知识,关于复合模式我有选择性地忽略了它,因为我暂时用不上。

1.全屏显示:

就是在set_mode函数里面将第二个参数传入FULLSCREEN,

主要代码:


while True:    for event in pygame.event.get():        if event.type == QUIT:            exit()        if event.type == KEYDOWN:            if event.key == K_f:                print("Hello")                Fullscreen = not Fullscreen                if Fullscreen:                    screen = pygame.display.set_mode((640,480),FULLSCREEN,32)                else:                    screen = pygame.display.set_mode((640,480),0,32)


还有一个比较有用的函数是pygame.display.list_modes(),显示电脑支持的显示模式


2.窗口尺寸改变显示:

在set_mode函数里面传入参数RESIZEABLE,然后用VIDEOSIZE这个事件来接收你对窗口尺寸改变的动作,

VIDEOSIZE这个事件有SIZE,W,H这三个参数,SIZE就是宽和高,w是宽,h是高,w和h可用可不用,改变尺寸之后要重新画窗口

主要代码:

while True:    event = pygame.event.wait()    if event.type == QUIT:        exit()    if event.type == VIDEORESIZE:        SCREEN_SIZE = event.size        screen = pygame.display.set_mode(SCREEN_SIZE, RESIZABLE, 32)        pygame.display.set_caption("Window resized to " + str(event.size))    screen_width, screen_height = SCREEN_SIZE    # 这里需要重新填满窗口    for y in range(0, screen_height, background.get_height()):        for x in range(0, screen_width, background.get_width()):            screen.blit(background, (x, y))
我不是太赞同该作者填充的方式,但是我也还不会,只能先将就了。
ps:我在写这篇博文的时候,室友正在一旁玩游戏,心里偷笑~

原创粉丝点击