Closed zejunli closed 2 years ago
@zejunli I'll take a look at this, but in general my experience has been that SDL2 and tkinter don't get along too well, sometimes in weird ways. Last time I tried to use the two together was a few years back, where using a Tk-created window instead of an SDL2-created one resulted in my program segfaulting whenever I tried to quit, but only on some versions of some OSes. After that experience I've adopted a pure-SDL2 windowing approach wherever possible.
I'm sure you've got a good reason, but is there a specific practical reason SDL2's windowing won't work for your use-case? Only asking because my reason for Tk was because I didn't realize SDL2 also offered resolution detection, so maybe you might be in a similar boat.
As for C++ embedding, I'm guessing you'd want to take a look at Pybind11 or maybe Cython (the former has better C++ support, the latter is more popular) to make a Python API for your C code. No clue if it's possible to pass windowing off to Python's Tk with that method, though.
@zejunli I'll take a look at this, but in general my experience has been that SDL2 and tkinter don't get along too well, sometimes in weird ways. Last time I tried to use the two together was a few years back, where using a Tk-created window instead of an SDL2-created one resulted in my program segfaulting whenever I tried to quit, but only on some versions of some OSes. After that experience I've adopted a pure-SDL2 windowing approach wherever possible.
I'm sure you've got a good reason, but is there a specific practical reason SDL2's windowing won't work for your use-case? Only asking because my reason for Tk was because I didn't realize SDL2 also offered resolution detection, so maybe you might be in a similar boat.
As for C++ embedding, I'm guessing you'd want to take a look at Pybind11 or maybe Cython (the former has better C++ support, the latter is more popular) to make a Python API for your C code. No clue if it's possible to pass windowing off to Python's Tk with that method, though.
Hi Austin, thanks for your reply, so what's going on here is me my team has a game engine developed in pure C++ using sdl2, we have also used pybind to build the engine into a python lib, so I initially was trying to fit this c++ sdl2 window somehow into a python GUI library window, where the python part will be a wrap-around panel that supports editing the game, i.e. adding stuff to the game using our engine API,I tried kivy and tkinter and both didn't end up having good result, so now we have to forsake this plan, we're trying to create another window to act like a control panel, I think embedding sdl2 into tkinter will lead us to more uncontrollable problems so that's also a part we consider, but this makes me wonder how those fancy GUI apps are developed, for instance VsCode and Sublime Text, they obviously have tons of control units in the GUI, what kind of lib/framework do they use?
@zejunli Your use of C++ might complicate things, but for the bare minimum of getting your C++ SDL2 code running through Python you can check out the PyBoy project for inspiration, which is a Python-based GameBoy emulator that I know uses compiled Cython SDL2 for windowing.
To my knowledge VSCode is built on Electron (which I think uses Chromium as a base) and TypeScript, so they're basically running a full web browser in an app to give you that kind of UI flexibility. For your use case you might want to give Qt5/PtQT5 or PySide a look, they offer a lot of flexibility for the kind of use case I think you're describing!
Just looked at this again: you may have figured out a different solution already, but it looks like SDL_CreateWindowFrom
takes ctypes pointer as an argument (pointing to platform-dependent window creation data), whereas your code is passing a string? That might be part of the problem.
Here is the code, I'm trying to embed sdl2 window into Tkinter window, but CreateWindowFrom causes the program to crash
Also, is it possible to embed a c++ sdl2 window into python tkinter window? Here is the reference: https://stackoverflow.com/questions/54404324/how-can-i-embed-an-sdl2-window-in-my-tkinter-gui-application