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!

NotMyName
  • 85
  • 1
  • 11

1 Answers1

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

mousetail
  • 7,009
  • 4
  • 25
  • 45
  • 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! – NotMyName Sep 16 '20 at 09:21
  • 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) – NotMyName Sep 16 '20 at 09:34
  • 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()` – mousetail Sep 16 '20 at 09:39