picandies
Posts: 186
Joined: Wed Nov 26, 2014 5:13 pm

Prevent Tkinter window minimize

Fri Mar 22, 2019 7:44 am

Hello, using tkinter on rpi3...I have a window & need to prevent it from being minimized.
Using root.overrideredirect(True) is not an option, since it removes the top bar & all 3 controls (min/max/close)

Even when I set root.resizable(width=FALSE, height=FALSE) , the window size can't be dragged, but the minimize button still reduces it! This needs to be prevented.
How could I get rid of only the minimize button? (preferred)
or, how can I respond to the minimize button event & restore the size?
Or another way of locking the size, so it can never be reduced, by any means?

klricks
Posts: 6491
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Prevent Tkinter window minimize

Fri Mar 22, 2019 12:57 pm

Use openbox config

Code: Select all

obconf
Click on [Appearance]
Remove "I" from the Button order:
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

picandies
Posts: 186
Joined: Wed Nov 26, 2014 5:13 pm

Re: Prevent Tkinter window minimize

Fri Mar 22, 2019 2:14 pm

Use openbox config
WHAT????!! this is a python program using tkinter...it this a python? or a tkinter command or library

How would you click on something? Your explanation needs redone.

picandies
Posts: 186
Joined: Wed Nov 26, 2014 5:13 pm

Re: Prevent Tkinter window minimize

Fri Mar 22, 2019 7:25 pm

How do you either:

1) Prevent the minimize button from functioning
2) Remove the only minimize button from the corner of the frame
3) Capture the minimize event & cause it to be undone (effectively ignored)

Andyroo
Posts: 3755
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Prevent Tkinter window minimize

Fri Mar 22, 2019 8:01 pm

Assuming root is the main window

Code: Select all

root.resizable(0,0)
should remove the max / min buttons IF the window manager lets you - some things under LINUX are not under control of the program (as in Windows) but in control of the window manager.

You could also try

Code: Select all

root.overrideredirect(1)
to totally remove the top part of the window (may be a bit overkill though)

You may want to look into the overrideredirect() function as well - this gives you more abilities but is more complex.
Need Pi spray - these things are breeding in my house...

klricks
Posts: 6491
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Prevent Tkinter window minimize

Fri Mar 22, 2019 11:09 pm

picandies wrote:
Fri Mar 22, 2019 2:14 pm
Use openbox config
WHAT????!! this is a python program using tkinter...it this a python? or a tkinter command or library

How would you click on something? Your explanation needs redone.
What I described is a global setting and will remove the minimize [-] from all program app dialogs including tkinter programs.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

picandies
Posts: 186
Joined: Wed Nov 26, 2014 5:13 pm

Re: Prevent Tkinter window minimize

Fri Mar 22, 2019 11:47 pm

Hi andyroo I don't think your suggestions do any of these
1) Prevent the minimize button from functioning
2) Remove the only minimize button from the corner of the frame
3) Capture the minimize event & cause it to be undone (effectively ignored)

Minimize is THE ONLY thing to be affected. The title bar must remain.


What I described is a global setting and will remove the minimize [-] from all program app dialogs including tkinter programs.
Not sure this is so good...things like the file browser will be affected?
Can you post the exact steps? I don't want to scrap my rpi & everything on it.

klricks
Posts: 6491
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Prevent Tkinter window minimize

Sat Mar 23, 2019 12:24 am

picandies wrote:
Fri Mar 22, 2019 11:47 pm
...

What I described is a global setting and will remove the minimize [-] from all program app dialogs including tkinter programs.
Not sure this is so good...things like the file browser will be affected?
Can you post the exact steps? I don't want to scrap my rpi & everything on it.
All windows will be instantly affected though it is easy to change it back.
I pretty much already gave step by step...
1. Open a terminal and type obconf then press [Enter]
2. Click on [Appearance] in left side pane.
3. Find under Window Titles..... Button order: [NLIMC]
4. Remove "I" from the Button order: [NLMC]
5. Close obconf and ignore error messages in terminal.

Note that Openbox Config Manager (obconf) can be added to the Preferences in main menu by using main menu editor.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

hippy
Posts: 5565
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Prevent Tkinter window minimize

Sat Mar 23, 2019 10:54 pm

klricks wrote:
Fri Mar 22, 2019 11:09 pm
What I described is a global setting and will remove the minimize [-] from all program app dialogs including tkinter programs.
I have to side with the OP here; what they want is a way to not have the minimise button appear in one particular program and/or for one particular form or dialogue. Not tweak any global settings which will have an effect on everything else.

I have done it myself, but can't remember how, it was using Python 2.7, and it might have still been there but disabled, or maybe even just did nothing when clicked. I recall it was a little problematic. If no one else can provide the answer I'll see if I can dig out what I did.

picandies
Posts: 186
Joined: Wed Nov 26, 2014 5:13 pm

Re: Prevent Tkinter window minimize

Sun Mar 24, 2019 4:44 am

I have done it myself, but can't remember how, it was using Python 2.7, and it might have still been there but disabled, or maybe even just did nothing when clicked. I recall it was a little problematic. If no one else can provide the answer I'll see if I can dig out what I did.
I'd sure appreciate it. @hippy ..I've come up dry. This is Python 3.5.3, latest, stretch and tkinter. Maybe using some type of wm_ setting?

gkreidl
Posts: 5996
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Prevent Tkinter window minimize

Sun Mar 24, 2019 7:04 am

Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

hippy
Posts: 5565
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Prevent Tkinter window minimize

Sun Mar 24, 2019 3:48 pm

picandies wrote:
Sun Mar 24, 2019 4:44 am
I have done it myself, but can't remember how, it was using Python 2.7, and it might have still been there but disabled, or maybe even just did nothing when clicked. I recall it was a little problematic. If no one else can provide the answer I'll see if I can dig out what I did.
I'd sure appreciate it. @hippy ..I've come up dry. This is Python 3.5.3, latest, stretch and tkinter. Maybe using some type of wm_ setting?
It could have been. I looked around but can't find any code for it. And I'm starting to suspect that whatever I would have had would have been for Windows, maybe using Win32.py (or whatever). I recall it was something I did while trying to get System Tray minimising working.

But maybe I am misremembering. I found stuff which removes both minimise and maximise, disables maximise or close, but not removes, disables or traps minimises. And all that code is for Windows.

Having searched on Google I can't find anything to do it either. It might be worth considering Qt, wx, or some other framework than Tkinter.

picandies
Posts: 186
Joined: Wed Nov 26, 2014 5:13 pm

Re: Prevent Tkinter window minimize

Mon Mar 25, 2019 10:25 pm

How do you capture the minimize event (when you click on _ in the window corner). At least then I can have the callback maximize it.

Is this actually doing an iconify? (not sure what that is), If so, how do you capture that?

gkreidl
Posts: 5996
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Prevent Tkinter window minimize

Tue Mar 26, 2019 8:50 am

picandies wrote:
Mon Mar 25, 2019 10:25 pm
How do you capture the minimize event (when you click on _ in the window corner). At least then I can have the callback maximize it.

Is this actually doing an iconify? (not sure what that is), If so, how do you capture that?
root.bind("<Unmap>"....

https://stackoverflow.com/questions/383 ... in-tkinter
https://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm#M13
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

hippy
Posts: 5565
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Prevent Tkinter window minimize

Tue Mar 26, 2019 9:47 am

gkreidl wrote:
Tue Mar 26, 2019 8:50 am
root.bind("<Unmap>"....
Not perfect, but this bounces the "tool window" back to how it was whenever it is minimised -

Code: Select all

import Tkinter as tk

class App:
  def __init__(self):
    self.root = tk.Tk()
    tk.Label(self.root, text="main window").pack()
    self.t = tk.Toplevel()
    tk.Label(self.t, text="tool window").pack()
    self.t.bind("<Unmap>", self.OnUnmap)
    self.root.mainloop()

  def OnUnmap(self, event):
    self.t.wm_deiconify()

app = App()

picandies
Posts: 186
Joined: Wed Nov 26, 2014 5:13 pm

Re: Prevent Tkinter window minimize

Tue Mar 26, 2019 8:53 pm

Thanks for the good info (never heard of "unmap") & also the sample code---about to go give it a try!

Return to “General discussion”