As we discussed in the comments, I doubt you can do it using pure tkinter.
I've tried to implement a solution for getting the window size including the border using win32gui. From this information you should be able to implement the rest of the functionality. Unfortunatly this is only for Windows platforms and requires an installation on pywin32. You can get it here. I'm sure there's a Mac and Linux equivalent if that is a requirement.
This is my solution, tested in Python 3.4:
import tkinter as tk
import win32gui
class TestApp:
def __init__(self, master):
frame = tk.Frame(master)
frame.pack()
self.master = master
label = tk.Label(text='Test Label')
label.pack()
b1 = tk.Button(text='test', command=self.pressed)
b1.pack()
def pressed(self):
win32gui.EnumWindows(self.callback, None)
x = root.winfo_x()
y = root.winfo_y()
w = self.master.winfo_width()
h = self.master.winfo_height()
print('tkinter location: ({},{})'.format(x, y))
print('tkinter size: ({},{})'.format(w, h))
def callback(self, hwnd, extra):
if "Test title" in win32gui.GetWindowText(hwnd):
rect = win32gui.GetWindowRect(hwnd)
x = rect[0]
y = rect[1]
w = rect[2] - x
h = rect[3] - y
print('Window location: ({},{})'.format(x, y))
print('Window size: ({},{})'.format(w, h))
root = tk.Tk()
root.title("Test title")
app = TestApp(root)
root.mainloop()
I'm win32gui.EnumWindows() to interate over all available windows to locate the one with the correct title. From this I can then get the size using win32gui.GetWindowRect().
I'll print the results from win32gui and tkinter to the console for comparison.