pythonborderlesspysdl2

PySDL2: Creating a borderless window


I've been trying to find how I might create a borderless window (One not created using the typical windows border) in PySDL2.

I've looked at what resources I could find online, but haven't been able to pinpoint anything that would tell me how to accomplish this, despite it being apparently possible.


Research:

  1. This link states that in most cases you have a border and title bar around your window, but never went into any more detail as to how to manipulate it.

  2. I looked at some API references for SDL's Window, and did not see that borders could be manipulated at all. (Not stated that they couldn't be, just no mention)


Despite not finding anything PySDL2 related, I did find at this link that:

sdl.setWindowBordered(window, bordered)
Sets the border state of a window.

Unfortunately, I'm unable to get this to work within my simple example script.

Thanks for looking!


Solution

  • You need to make sure you have the flag: SDL_WINDOW_BORDERLESS.

    Full example:

    import sys
    import sdl2.ext
    
    sdl2.ext.init()
    
    window = sdl2.ext.Window("Hello World!", size=(640, 480), flags=sdl2.SDL_WINDOW_BORDERLESS)
    window.show()
    
    processor = sdl2.ext.TestEventProcessor()
    processor.run(window)
    

    Modifying your script slightly we get:

    import sys
    import sdl2.ext
    
    def run():
        sdl2.ext.init()
        W = sdl2.ext.Window("Default",size=(400,300), flags=sdl2.SDL_WINDOW_BORDERLESS)
        W.show()
        running = True
        while running:
            events = sdl2.ext.get_events()
            for event in events:
                if event.type == sdl2.SDL_QUIT:
                    running = False
                    break
            W.refresh()
        return 0
    
    if __name__ == "__main__":
        sys.exit(run())