Search code examples
python-3.xtkinterfullscreenresizable

tkinter window changes size in zoomed state when made unresizeable


I came across the problem that I want to have a (initially) fullscreen window which sometimes should be resizeable and sometimes not. But I found that (on windows) when I make it unresizeable it changes its size to fill the complete window including the taskbar which I don't want it to do. I want it to stay the size it initially was when I have set it zoomed (obviously).

  • OS: Windows 10 Home
  • Python: 3.7
  • Tk/Tcl: 8.6

Reproducable example:

from tkinter import Tk

root=Tk()
root.state('zoomed') #until here is everything normal
root.resizable(False,False) #here taskbar gets hidden
root.mainloop()

Solution

  • Finally,I got this,Is this what you want?

    from tkinter import *
    
    def SetSize():
        width, height, X_POS, Y_POS = root.winfo_width(), root.winfo_height(), root.winfo_x(), root.winfo_y()
        root.state('normal')
        root.resizable(0,0)
        root.geometry("%dx%d+%d+%d" % (width, height, X_POS, Y_POS))
    
    root=Tk()
    root.state('zoomed') #until here is everything normal
    root.after(100,SetSize)
    root.mainloop()