gpt4 book ai didi

user-interface - 在 pygame 中添加 wxpython

转载 作者:行者123 更新时间:2023-12-04 15:25:58 24 4
gpt4 key购买 nike

我正在寻找一种可以将 wxPython GUI 元素添加到 pygame 中的方法。如果有替代方法可以解决将 GUI 元素添加到 pygame 的目的,请提出建议。我在安装 PGU 时遇到问题。感谢您的帮助。

最佳答案

不;您可以将 wxWidgets 添加到 PyGame。添加打开/保存对话框、按钮等是微不足道的。有时当您尝试共享区域时会变得令人讨厌(如上所述,存在冲突的窗口系统),但这绝对是可行的。

我是几年前写的,所以很乱;但至少它很简单。它应该可以帮助您入门:

class SDLThread:
def __init__(self,screen):
self.m_bKeepGoing = self.m_bRunning = False
self.screen = screen
self.color = (255,0,0)
self.rect = (10,10,100,100)
def Start(self):
self.m_bKeepGoing = self.m_bRunning = True
thread.start_new_thread(self.Run, ())
def Stop(self):
self.m_bKeepGoing = False
def IsRunning(self):
return self.m_bRunning
def Run(self):
while self.m_bKeepGoing:
pass
## GetInput()
## Draw()
self.m_bRunning = False;
class SDLPanel(wx.Panel):
def __init__(self,parent,ID,tplSize):
global pygame
wx.Panel.__init__(self, parent, ID, size=tplSize)
self.Fit()
os.environ['SDL_WINDOWID'] = str(self.GetHandle())
os.environ['SDL_VIDEODRIVER'] = 'windib'
import pygame
pygame.init()
icon = pygame.Surface((1,1));icon.set_alpha(0);pygame.display.set_icon(icon)
global Surface
Surface = pygame.display.set_mode(tplSize)
self.thread = SDLThread(Surface)
self.thread.Start()
def __del__(self):
self.thread.Stop()

关于user-interface - 在 pygame 中添加 wxpython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8798043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com