Unexpected window maximization

I am working on a python3 application to manipulate images. Resizing images is one of the functions. When I load an image that comes close to occupying the total screen area (somewhere to 5/6 part of total screen area) the encompassing top window “jumps/snaps” to the screen borders to the right and bottom (top system bar with date/time, and left taskbar are left alone). Once this happens the window will stick to the screen borders even when I resize the image to smaller dimensions. To pinpoint the problem I made my program as simple as possible, withdrawing all image manipulation and most widgets, and the problem still persists. In my most basic program I can load an image to a particular size without the window behaving strangely by becoming too big for its content (the image). But one pixel extra in height or width and the window jumps to the said screen borders. See program code and screen copies to better understand the problem. As this might be a problem of system configuration, these are my settings: OS: Linux Debian Buster, Python 3.7.3, Pillow 8.2.0

To be honest I asked this very same question on Stackoverflow but this has not produced any answer. So trying my luck with you guys. :grinning:

py3
import tkinter as tk

from PIL import Image,ImageTk

window = tk.Tk()

im = Image.open('./images/maxinput1092-846.jpg') 

#im = Image.open('./images/badinput1092-847.jpg') 

#im = Image.open('./images/badinput1093-846.jpg') 

photo = ImageTk.PhotoImage(image = im)

canvas = tk.Canvas(window, width = photo.width(),height = photo.height())

canvas.pack(expand = 0, fill = tk.BOTH, side = tk.BOTTOM)

canvas.create_image(0,0,image=photo,anchor="nw")

window.mainloop()

Screenshot of too big image size

Hi Rob,

this sounds like a behavior of the window manager your system is using. It is the very same what happens, if you resize a window manually (with your mouse) - in some window managers.

Maybe you can have a look into the settings of your window manager - maybe you’ll find a belonging setting there and can switch that off?

Cheers, Dominik

hi Dominik, first of all: thanks for your willingness to help. What you say about the erratic behaviour possibly being the work of a window manager sounds plausible to me. So, I have been looking into this. Problem is that I am not very well versed in this area of OS. The file /etc/X11/default-display-manager gives me gdm3, so the gnome 3 display manager. And the command “update-alternatives --list x-window-manager” gives me “mutter” as the window-manager. When I log in I get to choose from 4 gnome environments, of which I always choose “system X11 default”. I tried the other options (like Gnome classical) but same “window snapping” behaviour. I tried to look for configuration files for mutter. But I cannot find info on them on the internet. I can tweak Gnome via Gnome-tweaks. There is a section on windows, with an option to attach modal dialogs. I tried that setting, but no success. There are really few options I can set with tweaks. I post you a screenshot of the window tweaks. If you know where to look, please direct me. If not, thanks for your help anyway.

Hi Rob,

This almost certainly is nothing to do with Python. It will be a
“feature” of your window manager. Unfortunately each window manager is
different, but in XFCE you can control this misfeature by going to:

Applications > Settings > Window Manager

then click the “Advanced” tab, where there is a checkbox for “Window
snapping”.

Hi Rob,

I am not familiar with said constellation, but following Stevens hint

I googled “mutter window snap option” and got some hits, e.g.:

Another approach could be to forbid resizing said Tkinter-window, e.g.:

And last but not least you could write your own resize event slot, maybe this can set you on the track:

https://groups.google.com/g/comp.lang.python/c/tXHhx7Nx3-c

So, a lot to try, happy week end :cowboy_hat_face:

Cheers, Dominik

Hi Dominik,

thanks again so much for your help. Will follow up on your advice and report back my results

Rob

:dart:

Bullseye! I followed up on the first recommendation of Dominik, i.e.: How to activate window snapping in Gnome Shell? - Super User and entered the command:

gsettings list-recursively org.gnome.mutter

and got the output:

org.gnome.mutter attach-modal-dialogs true
org.gnome.mutter auto-maximize true
org.gnome.mutter overlay-key ‘Super_L’
(…)

setting the second item ‘auto-maximize’ to false, solved my problem of unexpected and unwanted window maximization. See the output:

1 Like

Congratulations!

Cheers, Dominik

thanks Dominik

1 Like