pythontkinter

Using Tkinter, is there a way to get the usable screen size without visibly zooming a window?


You can get the usable screen size (screen minus task bar, regardless of where it sits) like this:

import Tkinter as tk
root = tk.Tk()
root.state('zoomed')
root.update()
usable_width  = root.winfo_width()
usable_height = root.winfo_height()

Is there a way to do it that is not visible to the user? In Tkinter, 'withdrawn' (hidden) and 'zoomed' are mutually exclusive states.

You can get the total screen size by adding:

total_width  = root.winfo_screenwidth()
total_height = root.winfo_screenheight()

So far I've been unable to find a way to do this. Any ideas?


Solution

  • You can call:

    root.attributes("-alpha", 0)
    

    after creating the window. This will make it invisible, and then you can perform size calculations in the same way you already are.