Search code examples
pythontkinter

How can tkinter detect width of task bar on windows so that fullscreen doesn't cover the taskbar?


I am trying to make a fullscreen window with tkinter but the window covers the whole screen including the windows taskbar.How do i make the window fit nicely into the screen without covering the taskbar? Here is my source code:

from tkinter import*
my_window = Tk()

my_window.title("Demo")

screen_width = my_window.winfo_screenwidth()
screen_height = my_window.winfo_screenheight()

x = (screen_width /2) - (width_of_window/2)
y = (screen_height/2) -(height_of_window/2)

my_window.geometry("%dx%d+0+0"%
(my_window.winfo_screenwidth(),my_window.winfo_screenheight())

my_window.mainloop()

I am coding in windows 10 using vs code.


Solution

  • This seems to be a difficult task. The easiest way I have found is to:

    my_window.wm_state('zoomed')
    

    This corresponds to maximized, but not fullscreen. This does not seem to work on all platforms.

    Also see tkinter python maximize window