0

I programmed a board game in pygame, which is cool and all but I'd like to put it in a tkinter window so that I have space above my game, in which I can put buttons for resetting the board, etc.

How do I embed this? I would like to only have a tkinter window and not a seperate pygame window.

I made a window using

win = pygame.display.set_mode((WIDTH, HEIGHT)
pygame.display.set_caption('Game')

And then I displayed it using a while loop with

pygame.display.update()

I genuinely don't know how to make a tkinter that embeds this.

I tried using this solution, however when I ran this program I got two windows, which isn't what I want

L Ave
  • 13
  • 2
  • Would you mind attaching some screenshots and code that you're using to display the pygame window? It will help to see how you have done it to find the easiest way to do this. – SnNeposis Jan 09 '23 at 14:13

1 Answers1

1

This is complicated. Both toolkits have their own windowing subsystems.

I remember once coming across a way to have Pygame's SDL render into a canvas in another window - but I can't now recall if that was X11 (~Linux) specific.

You will jabe to either have your buttons and controls rendered by Pygame - in that case there are complementary libraries such as Phil's Pygame Utilities ("PGU" - I have republished a version of it for Python3 https://pypi.org/project/pygame-pgu/ ) or another similar library.

Another option is to have your game application use 2 independent, related windows - in this case, running tkinter in a separate thread should be enough to have both working - or calling the .update() method on the root tkinter object in the pygame mainloop should suffice.

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • 1
    Thanks, I think I will just make pygame buttons. Idk why I thought of tkinter it's really not necessary – L Ave Jan 09 '23 at 14:24
  • yep. the problem is that pygame really requires one to make any widgets from scratch. buttons are easier, but if you need any text entry, maybe the "cheaper" method is really to have a pop-up tkinter window. – jsbueno Jan 09 '23 at 14:29