Let's say you have quite a few windows into a process of registering a person's data. You then have a confirmation window at the end that needs to be closed before doing anything else (the window should either be closed by pressing 'Submit' or 'Cancelled'). Is there a way how to do this in tkinter python? The only example I could find to actually give a visual of what I mean is in the properties of a file (https://imgur.com/a/DO6cvlw)
Related
How can I can a function and create a function for the icon context menu? I want to make the iconic Open New Window function pop-up when you right click on the icon menu in the taskbar/dock. See this question for more info on this kind of question.
Places I have looked but found nothing:
https://www.tcl.tk/man/tcl8.5/TkCmd/tk_mac.html#M15
https://pyinstaller.org/en/stable/feature-notes.html#open-event-handling-in-a-tkinter-based-gui-application
While there are a tiny subset of apple events that you can benefit from the DockMenu is not accessible directly via tkinter. Turns out mac is not really open for modifications and even smaller tasks can be hard. You could consider to use a system tray icon instead.
I was wondering if anyone knew of a way to have a window open once another window closes after a certain amount of time with tkinter? I know the after command will help close a window after a specified time and I've implemented that, but is there a way to get a subsequent window to open after that same amount of time?
Is it possible to use tkinter to stop a user from clicking off my application. In other words making my program the top level program at all times?
The concept you are looking for is called a "grab". Tkinter supports grabs with several methods.
To do what you want requires a global grab, which effectively freezes your entire display except for your specific window. This is very dangerous since you can easily lock yourself out of your own computer if you have a bug in your code.
For more information, read about grab_set and other grab commands here: http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.grab_set-method
PyQt4/5 on OSX El Capitan
I have a QMessageBox/QDialog which I want to be modal and want to block input from other GUI items while a process is running. The QDialog should provide the user the option to cancel the said process, but not allow him or her to do anything else with the GUI in the meantime.
Once the process is finished, it should close the QDialog and enable input to the main application again. Because things should happen in the background while the dialog is shown, I am not using exec_() to display the dialog.
Here is a simple example of my code:
self.openingDialog = QtWidgets.QMessageBox(self.main_window)
self.openingDialog.setText(_(u"Opening experiment. Please wait"))
self.openingDialog.setStandardButtons(QtWidgets.QMessageBox.Cancel)
self.openingDialog.reject.connect(<some_function>)
self.openingDialog.show()
self.openingDialog.raise_()
... [Perform process] ...
self.openingDialog.done(0)
self.openingDialog.close()
self.openingDialog.deleteLater()
Everything works nicely in the sense that the dialog box is shown, and that no interaction is possible with other GUI elements while it is displayed. However, when has process is finished, the dialog box is automatically closed but it is still not possible to interact with other GUI elements afterwards. The GUI does not respond to mouse clicks, menu items are not accessible, and you can't even click the close button, so the application needs to be Force Quit.
What am I doing wrong in automatically closing the QDialog?
Ok, I have found sort of a workaround, although I don't think it is an elegant solution.
If I set the window modality to 'window modal' instead of 'application modal' by using:
self.openingDialog.setWindowModality(QtCore.Qt.WindowModal)
then the application regains focus and accessibility after the dialog has been closed by the program.
Still this doesn't solve the problem when the dialog is an application modal, but for now this serves my needs.
This question already has answers here:
Removing minimize/maximize buttons in Tkinter
(5 answers)
Closed 9 years ago.
Looking for advice on how to remove or disable a resizable window's maximize button under Windows. I'm using Python 2.7 for Windows.
Background: I have a resizable window with min and max sizes set via the window's minsize() and maxsize() methods. When a user clicks the maximize button, the window moves to the upper left of the display. This is very confusing to my users so I would like to prevent that behavior.
My research shows several ways to disable a maximize button - but none of these techniques seem to apply to resizable windows?
Prevent a window from resizing via the resizable( False, False ) method.
Remove all the window's controls (and border) via the overrideredirect( True ) method.
Use the mysterious transient(1) method (this raises an exception under Windows).
Bind the window's event and try to block the maximize (update: Tkinter has already maximized the window by the time our handler detects the maximize event. Returning "break" or using geometry(size|position) to size and re-position a window are both ignored)
I've posted a question on the Python Win32 API mailing list to see if we can use a Windows API call to disable a window's maximize button via the hWnd handle that I believe(?) Tkinter exposes.
Is there a way I can trap the maximize event (BEFORE Tkinter performs it)?
Malcolm
One possibility is to set the window as a tool window but this also comes with side effects; the window will no longer appear in the taskbar and will have a thin title bar. It will still be able to be resized at the edges.
root.attributes("-toolwindow", 1)
More about the root attributes can be found in this guidebook.