I made a music player, Once the main frame is iconized another frame appears and once that frame is iconized a smaller frame appears. Is there a way to get the last, small frame, to always be on the screen? now if I click outside of the frame it disappears until I click on it in the taskbar. I want it to always be on screen until the user clicks a button to open up the frame before the final, small frame.
To make the dialog stay in the foreground until the user interacts with it use the ShowModal() method:
There are two types of dialogs. Modal and modeless. Modal dialog does
not allow a user to work with the rest of the application until it is
destroyed. Modal dialogs are created with the ShowModal() method.
Dialogs are modeless when called with Show().
http://wiki.wxpython.org/AnotherTutorial/
If you just want the window to stay in the foreground, you can use the setFocus() method on the dialog because it is a child of the Window class:
SetFocus(self)
Set's the focus to this window, allowing it to receive keyboard input.
http://wxpython.org/docs/api/wx.Window-class.html#SetFocus
Related
In tkinter I am creating a Toplevel widget to prompt the user with "Are you sure you want to exit?" every time they try to exit my application. While this is happening, I want the Toplevel widget to have full focus of my application and the user to be unable to click anything on the root window, if possible.
While trying to figure out to do this, I discovered grabs and the ability to set the focus of the application. What is the difference between these two things?
Thanks in advance.
Focus means that your window will receive all keyboard events until some other window gets the focus. A grab tells the window manager that your window should have the focus until you explicitly tell it that it is allowed to take it away (ungrab).
I try to create a modal dialog using Python Tkinter. I found no difference between using and not using wait_window().
import tkinter as tk
def button_click():
dlg = tk.Toplevel(master=window)
tk.Button(dlg, text="Dismiss", command=dlg.destroy).pack()
dlg.transient(window) # only one window in the task bar
dlg.grab_set() # modal
#window.wait_window(dlg) # why?
window = tk.Tk()
tk.Button(window, text="Click Me", command=button_click).pack()
window.mainloop()
I've seen some examples in that use wait_window() for creating a modal dialog. So I'm not sure whether the function is required for creating a modal dialog.
I'm using Python 3.5.
Strictly speaking, no, wait_window() is not required to make a modal dialog box. What makes a dialog modal is the grab that you put on the window.
Often, however, once the window is destroyed you may need to run some other code. You can use wait_window() for this purpose, as it will wait for the window to be destroyed before continuing. You can then have code after that, such as a return statement, or some cleanup code. In your case there's nothing to do, so you don't need to call wait_window.
running your code using window.wait_window(dlg) won't change anything as dlg.grab_set() already creates a modal dialog. this does only mean that you cannot close window while dlg is still alive. you cannot close window as the modal dialog grabs all mouse events from window and redirects them to null.
If you want to create a modal dialog without grab_set(), you would need to bind all mouse events to one handler and then decide if they should be allowed or dismissed and use wait_window.
As a modal dialog is defined by "is anything outside the dialog and in my application available to be clicked" == False , you already have a modal dialog only using grab_set().
If your application shall not be able to programatically close window, you would need wait_window() as well.
Hope I made everything clear.
Python 2.7, PyQt4.8.5
I want to have a main app window and then a second pop up window to display com port settings. This window should always be on top of the parent window until either the ok or the cancel button is clicked; closing the child window. (sort of like a required answer i.e. cant process until you choose the settings from the child window)
Is there a Python Qt command to do this?
Apologies if this has been asked/answered before, my search returned nothing useful.
You want a modal dialog. For example:
dialog = QInputDialog()
dialog.exec_()
You can either implement your own dialog widget (by subclassing QDialog) or use one of the several available.
In Tkinter I'm trying to make it so when a command is run a widget is automatically selected, so that a one may bind events to the newly selected widget.
Basically I want it so when I press a button a text widget appears. When it appears normally one would have to click the text widget to facilitate the running of events bound to the text widget. I want that behavior to automatically happen when the user clicks the button. So that one does not have to click the button and then the text widget, but simply the button.
I'd also like it so if one started typing after the button was pressed it would automatically start filling the text widget. Again to cut out having to click on the text widget.
What bit of code does the above?
The terminology which describes what you want is "focus" -- you want to set the keyboard focus to your text widget. To do that you need to use the focus_set() and/or focus_force() methods on the text widget.
I'm building an app that uses global shortcut keys (using python-keybinder), but there's a problem. The frame pops up and raises properly but doesn't have focus. I have to click on frame.
After I press my keyboard shortcut my frame appears, but it is not focused. I can see that the frame I was focused on previously (e.g. my Firefox frame) still has focus (i.e., the title bar is still white & bold). Only after I click on my app's frame does Firefox's title bar become grey and dim.
I try to SetFocus and CaptureMouse but neither do anything. FindFocus and GetCapture return None.
This only happens on Ubuntu (GNOME). On Windows, the frame gets focus immediately. Is there a way to force GNOME to give focus to my app/frame?
How are you showing the frmae initially, with frame.Show()? I'm not sure if you're saying the frame itself doesn't have focus (but/or a child of the frame does), or your application doesn't have focus?
Are you calling SetFocus in the Frame that initialises all your widgets? It could be an issue of the focus being given to a child of the frame. Try using wx.CallAfter(self.SetFocus) at the end of your Frame.init method - it should ensure the focus is set after all widget creation is done