tk_checkbutton.py

# =========================================================
# Code based on:
#     www.python-course.eu/tkinter_checkboxes.php
# =========================================================

# --- am I running Python 2 or 3

import sys

if sys.version_info.major is 3:
    from tkinter import *
    py3 = True
else:
    from Tkinter import *
    py3 = False

# --- checkbox callback?

def CB():
    w = c.winfo_width()
    h = c.winfo_height()
    print('checkbox: w={},h={}'.format(w,h))
    w = root.winfo_width()
    h = root.winfo_height()
    print('root: w={},h={}'.format(w,h))

# --- root window

root = Tk()

# --- do no alllow resize

root.minsize(width=100,height=100)
root.maxsize(width=100, height=100)

# --- create check button

var = IntVar()

c = Checkbutton(root, text='Expand', variable=var,
        font=('arial', '15'), command=CB)
c.pack()

# --- size of widget?
# --- Note that if you call this code before the window
# --- appears on the screen, you won't get the answer
# --- you expect. Tkinter needs to have actually drawn
# --- the window before it can know the size. So the
# --- following code is bogus. Try a callback function
# --- when the button changes.

w = c.winfo_width()
h = c.winfo_height()
print('w={},h={}'.format(w,h))

# --- event loop

mainloop()