I'm trying to figure out how to get the height of a tkInter window title bar but can't seem to find any info on how it's done.
I have tried using root.geometry()
and it seems that root.geometry()
only returns the size of the window content and not the total size of the window with title bar and border sizes. I have seen other people say that you need to ask the OS for those things. I was hoping to avoid this because it will make it harder to make the code platform independent. There must be a way to do this without going to the OS for this. Anyone know what it is I must do to get this info?
My system:
OS: Linux
KDE Plasma: 5.16.4
KDE Frameworks: 5.61.0
import tkinter
root = tkinter.Tk()
root.geometry("250x250+100+100")
root.update_idletasks()
print('root.winfo_x() = ', root.winfo_x())
print('root.winfo_y() = ', root.winfo_y())
print('root.geometry() = ', root.geometry())
root.mainloop()
Test code results:
root.winfo_x() = 100
root.winfo_y() = 100
root.geometry() = 250x250+100+100
The height of the window when measured with a screen ruler app is:
x=102, y=286
(0, 22)
which ist the height of the titelbar. Edit your question and show your attemp. – Poltroon(101, 122)
, so it may depend from the usedOS Window Manager
. I use Linux LXDE. – Poltroon,
frame.winfo_rootx(),
frame.winfo_rooty()` – Poltroontkinter
provides a littlebit interaction with it, like icon or title, unfortunately, geometry isn't a case. For example, on window system you can use GetSystemMetrics(SM_CYCAPTION) for your task. Another direction could be detecting a geometry of both client and non-client area of your window and do math. – Laureentkinter
a window decoration is platform dependent. Thus, you or someone else will add these dependencies one way or another. Don't run away from it. – Laureen