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?
'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()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With