PyGame GUI在Windows上变得无响应,在Linux上运行良好

时间:2018-08-23 17:23:50

标签: python windows pygame

我似乎无法弄清楚Windows为什么认为pygame GUI没有响应。当我在下面运行我的类时,GUI线程(self.update_thread)和默认线程都可以正常运行,但是GUI窗口冻结。

class WorldDisplayer(object):
    def __init__(self, world, size=(640, 480)):
        """
        Create a ``WorldDisplayer`` object with a given map.

        Creates a ``WorldDisplayer`` object, which opens a PyGame window and
        draws ``world``, then allows operations on ``world``, which redraw the
        world if necessary. The window size defaults to 640x480, but can be
        set on initialization.

        :param world: The world to display and manipulate
        :param size: =(640 480) The size of the window
        """
        self.w = world
        self.size = size
        self.disp_surf = pyg.display.set_mode(self.size,RESIZABLE)
        self.tile_size = (self.size[0]/self.w.dim,
                          self.size[1]/self.w.dim)
        self.select_goals = False
        self.goal_locs = set()

        self.update_thread = Thread(target=self.update_loop)
        self.update_thread.daemon = True
        self.update_thread.start()

    def update_loop(self):
        """
        Continuously update the canvas and listen for events

        :return: None
        """
        while True:
            self.draw_world()
            events = pyg.event.get()
            for event in events:
                print("event before is {}".format(event))
                self.on_event(event)
                print("event after is {}".format(event))
            pyg.display.flip()
            pyg.display.update()
            sleep(0.1)
            print("running")

调试时,我注意到发生了以下事件:

event before is <Event(17-VideoExpose {})>
Received unknown event <Event(17-VideoExpose {})>
event after is <Event(17-VideoExpose {})>

event before is <Event(16-VideoResize {'h': 480, 'w': 640, 'size': (640, 480)})>
Received unknown event <Event(16-VideoResize {'h': 480, 'w': 640, 'size': (640, 480)})>
event after is <Event(16-VideoResize {'h': 480, 'w': 640, 'size': (640, 480)})>

event before is <Event(1-ActiveEvent {'state': 1, 'gain': 0})>
Received unknown event <Event(1-ActiveEvent {'state': 1, 'gain': 0})>
event after is <Event(1-ActiveEvent {'state': 1, 'gain': 0})>

event before is <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (318, 0), 'rel': (319, 0)})>
Received unknown event <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (318, 0), 'rel': (319, 0)})>
event after is <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (318, 0), 'rel': (319, 0)})>

这些事件与我在linux上运行时的事件不同。我在linux上遇到的唯一事件是“ ActiveEvent”事件。其他三个事件之一(VideoExpose,VideoResize或MouseMotion)是否可能引起此问题?我尝试将pyg.display.set_mode()更改为包括RESIZEABLE,以防问题是由于VideoResize事件引起的,但是那没有用。有什么建议或我应该尝试的事情吗?谢谢!

0 个答案:

没有答案