4

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?

LMO
  • 515
  • 7
  • 18

2 Answers2

4

'zoomed' did not work for me in Linux Mint, but I finally found something that did and I think it is more portable. This can even be called while the window is withdrawn so that the user does not see the changes.

w, h = root.maxsize()
FeralBytes
  • 43
  • 3
3

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.

D K
  • 5,530
  • 7
  • 31
  • 45
  • 1
    Yes, that works. I'm finding that the method I showed in the example works pretty well on Windows, but on OSX it gives some odd results. – LMO Oct 30 '12 at 05:27
  • For anyone wondering, to undo this and make the root window visible again, use `root.attributes("-alpha", 1)`. – martineau Jan 14 '22 at 23:32