- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在运行 Jessie 的 Raspberry Pi 2 上有两个显示器:(默认)HDMI 显示器和一个 Adafruit PiTFT LCD。
我可以在两个 SSH 终端独立启动 pygame 程序,用于两个不同的显示,除了我运行的第二个暂停,直到我按下 ^C。
在我的 Mac 上使用 SSH,我可以在任何一个上运行“数到 50”的 pygame 程序。 (唯一的区别是 LCD 版本设置了 2 个将 pygame 重定向到 LCD 屏幕的环境变量。)
如果我打开两个 SSH 终端,并尝试运行两个 python 程序,第二个程序只有在我按下 control-C 时才会开始运行。
我需要做哪些不同的事情才能让第二个程序开始正常运行而无需先按 control-C?
我不确定这是“linux”设备设置问题还是“python”代码问题?
这是两个简单的程序:
# count_on_lcd.py
import pygame, time, os
# on raspberry pi this sends to LCD screen
os.environ['SDL_VIDEODRIVER'] = 'fbcon'
os.environ["SDL_FBDEV"] = "/dev/fb1"
pygame.init()
Screen = max(pygame.display.list_modes())
Surface = pygame.display.set_mode(Screen)
Surface.fill(pygame.Color(0,0,0))
pygame.display.update()
font_big = pygame.font.Font(None, 150)
for i in range(50):
print (i)
Surface.fill(pygame.Color(128,0,0))
text_surface = font_big.render('%s'%i, True, (255,255,255))
rect = text_surface.get_rect(center=(50,50))
Surface.blit(text_surface, rect)
pygame.display.update()
time.sleep(1)
Surface.fill(pygame.Color(0,128,0))
pygame.display.update()
time.sleep(1)
和
#count_on_hdmi.py
import pygame, time
# on raspberry pi the HDMI screne is default
pygame.init()
Screen = max(pygame.display.list_modes())
Surface = pygame.display.set_mode(Screen)
Surface.fill(pygame.Color(0,0,0))
pygame.display.update()
font_big = pygame.font.Font(None, 150)
for i in range(50):
print (i)
Surface.fill(pygame.Color(128,0,0))
text_surface = font_big.render('%s'%i, True, (255,255,255))
rect = text_surface.get_rect(center=(50,50))
Surface.blit(text_surface, rect)
pygame.display.update()
time.sleep(1)
Surface.fill(pygame.Color(0,128,0))
pygame.display.update()
time.sleep(1)
在我的 Mac 上,我打开两个连接到 Raspberry Pi 的 SSH 终端。
在第一个 SSH 终端中:
$ sudo python count_on_lcd.py
(starts running normally)
在第二个 SSH 终端中:
$ sudo python count_on_hdmi.py
(Pauses until I type ^C)
无论我以何种顺序启动这两个程序,它都会做同样的事情...我调用的第一个命令总是立即运行,我调用的第二个命令也需要一个 ^C 才能开始运行。
最佳答案
如果 pygame.init() 已经在单独的 SSH 终端中运行,这似乎是 pygame.init() 无法正常运行的问题。
我在 SO 上找到了解决方案。它不是很漂亮,但很管用。
仅对 pygame requires keyboard interrupt to init display 稍作修改
from signal import alarm, signal, SIGALRM, SIGKILL
def init_Pygame(surf):
# this section is an unbelievable nasty hack - for some reason Pygame
# needs a keyboardinterrupt to initialise in some limited circs (second time running)
class Alarm(Exception):
pass
def alarm_handler(signum, frame):
raise Alarm
signal(SIGALRM, alarm_handler)
alarm(3)
print("Step 2 ")
try:
pygame.init()
Screen = max(pygame.display.list_modes())
surf = pygame.display.set_mode(Screen)
alarm(0)
except Alarm:
raise KeyboardInterrupt
return (surf)
关于python - 在第二个 SSH 终端中运行第二个 pygame 程序(用于第二个显示)会暂停,直到按下 ^C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34981542/
Surface.blit在 1.8 中有一个新参数:混合。定义了以下值: BLEND_ADD BLEND_SUB BLEND_MULT BLEND_MIN BLEND_MAX BLEND_RGBA_A
import sys import pygame import pygame.locals as pgl class Test: def __init__(self): pyg
我对 PyGame 比较陌生。我正在尝试制作一个简单的程序来显示表示鼠标在屏幕上的位置的字符串。 import pygame, sys from pygame.locals import * pyga
我有总是在后台运行的音乐和一些在触发时会播放声音的事件。音乐效果很好。 pygame.mixer.music.load(os.path.join(SOUND_FOLDER, 'WateryGrave.
我有这些代码 FONT = pygame.font.Font("font/calibri.ttf", 50) FONT.size = 25 但是编译器说 AttributeError: 'pygame
有我正在导入的图像: look_1 = pygame.image.load('data\\png\\look1.png').convert_alpha() 我试图减少它的大小是这样的: pygame.
我正在为我的 pygame 制作一个帮助屏幕,每当我运行它时,我都会收到此错误消息: > self.surface.blit(self.helpscreen) TypeError: argument
在 pyGame 中应用程序,我想渲染 SVG 中描述的无分辨率 GUI 小部件。 我怎样才能做到这一点? (我喜欢 OCEMP GUI 工具包,但它的渲染似乎依赖于位图) 最佳答案 这是一个完整的例
有没有办法将多首歌曲加载到 Pygame 中?我不是在谈论这样的音效; crash_sound = pygame.mixer.Sound("crash.ogg") #and pygame.mixer.
我还有一个问题。当我尝试运行我的代码时,pygame 启动然后立即停止。 这是我的代码: import pygame import os import time import random pygam
我正在使用 pymunk 和 pygame 开发一个项目。我正在使用 PivotJoint 约束将我的 body 连接在一起。如果可能的话,我想让关节不可见 - 有什么办法可以做到这一点吗?现在关节在
我使用 fedora 20、Python 2.7 和 virtualenv 1.10.1。我想在 virtualenv 中安装 pygame,我得到了 You are installing a pot
尝试将文本添加到矩形中并使用箭头键在屏幕上移动矩形。我想让文字不会超出边缘。到目前为止,我已经在没有将其放入 Rect 中的情况下工作了,但我想让 Rect 函数工作。现在文本只是反弹回来,我不知道要
我是第一次玩 pygame(总的来说我是 python 的新手),想知道是否有人可以帮助我... 我正在制作一款小型射击游戏,希望能够为坏人创建一个类。我的想法是类应该继承自 pygame.Surfa
我在 Windows 10 机器上运行了 python 3.9.1。我通过 pip 在我的机器上安装了 pygame 2.0.1 (python -m pip install https://gith
错误: File "/home/alien/cncell/core/animator.py", line 413, in create_animation_from_data pygame
这是代码。 5000 个弹跳旋转的红色方块。 (16x16 png) 在 pygame 版本上,我获得 30 fps,但使用 pyglet 获得 10 fps。对于这种事情,OpenGl 不应该更快吗
我以为 pygame.font.Font 是用来加载 .ttf 字体的,如果没有 .ttf 文件在同一个目录下就无法加载字体,但我看过一个视频,有人在没有 .ttf 文件的情况下加载字体。 ttf 字
我正在尝试使用 Travis CI 设置一个项目。项目也使用 pygame。我曾多次尝试设置它 - 但它似乎失败了。 我得到的最接近的是以下内容: .travis.yml : language: py
这个问题已经有答案了: Python error "ImportError: No module named" (38 个回答) 已关闭 3 年前。 我正在使用 Mac 并输入 pip install
我是一名优秀的程序员,十分优秀!