2

I'm making a simple game using the Pygame Module. I require a Tkinter window to be open alongside the Pygame window.

Whenever I try to open both the windows, the second window only opens after I kill the first one.

Now, the only solution I can think of, is using multi-threading. But, I'm not able to implement it.

How do I go about this? I would really appreciate some help here. Thank You!

1 Answer 1

4

There is a fundamental design issue in pygame that makes it unable to open a window if the process already has a window. It will also prevent other windows from opening while it is running. However, you can open as many TK windows as you like and you can embed a pygame window inside a SDL drawing frame inside a TK window.

See this answer on how to use the drawing frame: Embedding a Pygame window into a Tkinter or WxPython frame

See this answer on how to create multiple windows in tkinter: How to open multiple windows in Tkinter

Sign up to request clarification or add additional context in comments.

3 Comments

I was able get what I wanted by setting the Tkinter frame-width = 0. Now it is pretty much like a Pygame Window and I can open multiple Tkinter Windows. Really Helpful!
I just have a question, I'm printing the values of the mouse position using pygame.mouse.get_pos() . But now the mouse position values do not update as I move it. It worked perfectly fine before embedding the Pygame window into a Tkinter window. But now, I have to click, only then I start getting the new position values(the place where I clicked)
I'm sorry I wouldn't know. It might be that the event system does not work by default in embedded windows, and you will need to detect events in tkinter and forward them to pygame with pygame.event.post()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.