When you change content of a gtk.Window it expands automatically, but does not shrink automatically. Here is a small workaround.
1
w.resize(*w.size_request())