Pygame with Multiple Windows

白昼怎懂夜的黑 提交于 2019-12-31 02:26:28

问题


I need to to build an application that has multiple windows. In one of these windows, I need to be able to play a simple game and another window has to display questions and get response from a user that influences the game.

(1) I was wanting to use pygame in order to make the game. Is there a simple way to have pygame operate with multiple windows?

(2) If there is no easy way to solve (1), is there a simple way to use some other python GUI structure that would allow for me to run pygame and another window simultaneously?


回答1:


The short answer is no, creating two pygame windows in the same process is not possible. If you want to run two windows with one process, you should look into pyglet or cocos2d.

An alternative, if you must use pygame, is to use inter-process communication. You can have two processes, each with a window. They will relay messages to each other using sockets. If you want to go this route, check out the socket tutorial here.




回答2:


Internally set_mode() probably sets a pointer that represents the memory of a unique display. So if we write:

screenA = pygame.display.set_mode((500,480), 0, 32)
screenB = pygame.display.set_mode((500,480), 0, 32)

For instance we can do something like that later:

screenA.blit(background, (0,0))
screenB.blit(player, (100,100))

both blit() calls will blit on the same surface. screenA and screenB are pointing to the same memory address. Working with 2 windows is quite hard to achieve in pygame.



来源:https://stackoverflow.com/questions/29811814/pygame-with-multiple-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!