How to make a window fullscreen in a secondary display with tkinter?

后端 未结 3 1337
無奈伤痛
無奈伤痛 2021-01-04 02:22

I know how to make a window fullscreen in the \"main\" display, but even when moving my app\'s window to a secondary display connected to my PC, when I call:



        
3条回答
  •  不知归路
    2021-01-04 03:17

    Windows, Python 3.8

    In this solution, pressing F11 will make the window fullscreen on the current screen.

    Note that self.root.state("zoomed") is Windows specific according to doc.

    self.root.overrideredirect(True) is weird in Windows and may have unwanted side effects. For instance I've had issues related to changing screen configuration with this option active.

    #!/usr/bin/env python3
    import tkinter as tk
    
    
    class Gui:
        fullScreen = False
    
        def __init__(self):
            self.root = tk.Tk()
            self.root.bind("", self.toggleFullScreen)
            self.root.bind("", self.toggleFullScreen)
            self.root.bind("", self.quit)
            self.root.mainloop()
    
        def toggleFullScreen(self, event):
            if self.fullScreen:
                self.deactivateFullscreen()
            else:
                self.activateFullscreen()
    
        def activateFullscreen(self):
            self.fullScreen = True
    
            # Store geometry for reset
            self.geometry = self.root.geometry()
    
            # Hides borders and make truly fullscreen
            self.root.overrideredirect(True)
    
            # Maximize window (Windows only). Optionally set screen geometry if you have it
            self.root.state("zoomed")
    
        def deactivateFullscreen(self):
            self.fullScreen = False
            self.root.state("normal")
            self.root.geometry(self.geometry)
            self.root.overrideredirect(False)
    
        def quit(self, event=None):
            print("quiting...", event)
            self.root.quit()
    
    
    if __name__ == '__main__':
        Gui()
    

提交回复
热议问题