无需启动到桌面树莓派即可运行 PyGame 程序 [英] Run PyGame program without booting to Desktop Raspberry Pi

查看:250
本文介绍了无需启动到桌面树莓派即可运行 PyGame 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Raspberry Pi 使用 PiTFT 显示器,我想在不启动到桌面的情况下运行我的 PyGame (Python) 程序.

I am using the PiTFT display for the Raspberry Pi, and I want to run my PyGame (Python) program without booting to the Desktop.

我想这样做的原因是因为它意味着更少的 RAM 使用量,这在 Raspberry Pi 上非常重要.以前有人问过这个问题,但没有一个答案是最新的,否则根本就没有用.

The reason I want to do this is because it will mean less RAM usage, and that is pretty important on a Raspberry Pi. This has been asked before, but none of the answers are up to date, or else never worked in the first place.

推荐答案

我不太清楚您遇到了什么问题,但这应该相当简单.

I'm not exactly clear what problem you're having, but this should be fairly straightforward.

当我使用 PiTFT 屏幕时,我在我的 pygame 脚本的顶部添加了这个(我的 Pis 都没有使用桌面环境):

I add this at the top of my pygame scripts when using the PiTFT screen (none of my Pis use the desktop environment):

import os
# Tell the RPi to use the TFT screen and that it's a touchscreen device
os.putenv('SDL_VIDEODRIVER', 'fbcon')
os.putenv('SDL_FBDEV'      , '/dev/fb1')
os.putenv('SDL_MOUSEDRV'   , 'TSLIB')
os.putenv('SDL_MOUSEDEV'   , '/dev/input/touchscreen')

然后你只需要确保你的 pi 不会启动到桌面环境.你可以通过运行:

Then you just need to make sure your pi doesn't boot into the desktop environment. You can do that by running:

sudo raspi-config

并更改相关设置.

这篇关于无需启动到桌面树莓派即可运行 PyGame 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆