1
votes

I have a stripped down piece of code below that first opens an empty tkinter window, and then, once that tkinter window is closed it will open a pyglet window.

How can I force these two windows to open at the same time?

There is a similar question at the link below about opening two tkinter windows at the same time using toplevel() but I do not believe it applies to my problem.

Thanks in advance

import pyglet
from tkinter import *

# Open's a tkinter window
root = Tk()
mainloop()

# Open's a Pyglet Window only after the tkinter window as been closed
class Window(pyglet.window.Window):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)


window = Window()
pyglet.app.run()
1

1 Answers

1
votes

Sorry guys. I clearly hadn't finished reading all the options. Revised code below seems to do the trick using Threading:

import pyglet
from tkinter import *
import threading
from threading import Thread


def run1():
    root = Tk()
    mainloop()


def run2():
    class Window(pyglet.window.Window):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
    window = Window()
    pyglet.app.run()


if __name__ == '__main__':
    Thread(target=run1).start()
    Thread(target=run2).start()