python之显示按键操作
来源:互联网 发布:linux 替换jar包文件 编辑:程序博客网 时间:2024/06/09 23:04
import pygameimport syspygame.init()bg = (0, 0, 0)size = width, height = 600, 400#设置界面尺寸screen = pygame.display.set_mode(size)#设置界面的标题pygame.display.set_caption("my name is zhaoshuo")#用实例化fontfont = pygame.font.Font(None, 20)#设置坐标position = 0line_height = font.get_linesize()while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() #用render方法将字体渲染surface对象 screen.blit(font.render(str(event), True, (0, 255, 0)), (0, position)) position += line_height if position > height: position = 0 screen.fill(bg) #更新界面 pygame.display.flip()
基本思路:
1.将尺寸初始化
2.在while True里将字体用pygame里的render方法将字体渲染成surface对象
外加一个将按键操作记录下来的程序:
import pygameimport syspygame.init()bg = (0, 0, 0)size = width, height = 600, 400screen = pygame.display.set_mode(size)pygame.display.set_caption("my name is zhaoshuo")f = open('record.txt', 'w')while True: for event in pygame.event.get(): f.write(str(event) + '\n') if event.type == pygame.QUIT: f.close() sys.exit()
0 0
- python之显示按键操作
- ARM之按键操作
- Python之mouse按键
- Android学习之按键操作
- Android学习笔记之按键操作
- android之隐藏状态栏,全屏显示和隐藏虚拟按键
- JavaScript语法学习笔记之 鼠标及按键操作
- python之文件操作
- Python之分片操作
- python之文件操作
- python之列表操作
- python之字典操作
- python 之文件操作
- python 之文件操作
- python之数据库操作
- python之邮件操作
- python之目录操作
- python之文件操作
- 面试问题汇总
- CodeForces 616A
- 221. Maximal Square(难)
- awk、cut、sort和uniq
- cocos2d-x-3.0学习笔记之如何添加菜单按钮
- python之显示按键操作
- M101P: MongoDB for Developers - Chapter 1: Introduction
- 【JZ雅礼联考】跳楼机 题解
- ListView复用导致checkBox错乱的解决方法
- Linux 共享库加载方法
- ConcurrentHashMap关于方法的深度解析
- 【KMP算法】KMP统计子串出现次数
- AndroidStudio——利用APIStore获取网络新闻
- MyBatis 基础