没有什么好说的,直接上代码吧:
# ------------------------------------------------------------------------------- # Name: pygame版hello world # Purpose: ## Author: garfield ## Created: 22-12-2011 # Copyright: (c) garfield 2011 # Licence: no # ------------------------------------------------------------------------------- # !/usr/bin/env python # -*- coding: utf-8 -*- import pygame def main(): # 初始化 pygame.init() # 设置屏幕大小 SCREEN_SIZE=(300,150) # 设置屏幕 screen=pygame.display.set_mode(SCREEN_SIZE,0,32) # 来个个性的红色底色吧,好的,我知道不怎么好看 screen.fill((255,0,0)) # 设置字体 font=pygame.font.SysFont( ' arial ',32) # 在鲜红的背景上写上码农们熟悉地想吐的hello world screen.blit( font.render( ' Hello,world ! ', True, (0, 0, 0)), (50, 50)) # 记住,一定要刷新显示 pygame.display.update() # 怎么退出程序?随你的便吧,这里就不加了 if __name__ == ' __main__ ': main()
效果: