简体   繁体   中英

Pyglet running multiple windows

I have problem when running some test code. There is a lot of code so I will paste only summary of a problem:

import pyglet

class Test(object):
    def setUp(self):
        self.window = pyglet.window.Window()

    def tearDown(self):
        del self.window

    def wtf(self):
        self.setUp()
        self.tearDown()
        self.setUp()
        pyglet.app.run()

test = Test()
test.wtf()

I would expect upper code to open 1 window, however it opens 2.

How can I fix this problem?

import pyglet

class Test(object):
    def setUp(self):
        self.window = pyglet.window.Window()

    def tearDown(self):
        self.window.close()
        del self.window

    def wtf(self):
        self.setUp()
        self.tearDown()
        self.setUp()
        pyglet.app.run()

test = Test()
test.wtf()

You can also use set_visible in order to hide it as a temporary thing if you want to show it later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM