Closing an .ui file on a click of a button (pyqt5) - python

I need my dialog box to close when the ok button is clicked. How do I do that ?

Assuming you created the button you should be able to just set the button click event as follows:
button.clicked.connect(self.close) where button is the button name.
Although since you did not provide any code with your question it's hard to know if this is what you're asking for...

Related

Is there a way to make an invisible button in Tkinter?

I found ways to hide something after pressing a button, but what I would like to do is having an invisible button that can still be pushed. A secret button of some sort, using Tkinter. It doesn't need to do anything yet
You don't need an invisible button to register a secret click Simply bind <1> to the root window and it will register whenever you click on anything (unless you click on some other widget that is listening for that event). You can then check the coordinates of the click to see where the use clicked.

Is wait_window() required for creating a modal dialog in Python Tkinter?

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.

Make a click event in Tkinter

I'm trying do a very simple task: Make a Button click in Tkinter.
I have an array of Buttons and, when I finish an event, I want to make a Button click event in one of my buttons.
I thought it should be as simple as buttons[2].click(), but that doesn't do anything.
Try calling .invoke() on the button

Qt Designer: how to add custom slot and code to a button

I use Qt4 Designer and I want that when I click on the "yes" button, some code will execute. And when I click on the "no", some other code will be execute. How can I do it?
Click on the Edit Signal/Slots tool.
Create a connection for your button. For this, select your button in the designer by pressing on it with the left button of the mouse. Move the mouse to some place in the main window to create a connection with the main window (it is like a red line with a earth connection).
When you release the mouse button, the Configure Connection dialog appears.
In this dialog select a signal in the left text control (the sender), for example, pressed().
Then press edit in the right text control (the receiver). A dialog for the Signals/Slots of MainWindow appears.
In the slot panel add a new slot (green cross). The text slot1() appears. Double click on it to edit the line and write instead the name of your function doit_when_yes_ispressed(). Accept.
Now in the Configure Connection dialog you will see your function in the right text control. Select and Accept.
In the designer now you can see the signal and your function in the widget.
Right-click on your widget
Select "Go to slot..."
Select a signal and click OK
Your custom slot declaration and definition for that signal will be added to *.cpp and *.h files. Its name will be generated automatically.
upd:
Sorry, I didn't notice that the question is about Python & QtDesigner itself, I was thinking of the designer mode in QtCreator IDE. However, this still may be useful for someone who is looking for Qt/C++ info, so I leave the answer.

How do I disable a button after it's clicked in wxpython?

There are two buttons in my little program, start and stop. And what I want is to disable the start button after I click it, and when I hit the stop button it should return to normal. How can I do this? I googled for a while and couldn't find the answer, hope you guys can help me out.
Thanks!
Use the button's Enable and Disable methods in the appropriate event handlers. There's a sample available at the link below:
wxPython Button Demo
In this snippet we are playing around with wxPython's buttons, showing you how to bind the mouse click event, enable and disable, show and hide the buttons. Each button also has a tool-tip (hint) associated with itself.

Categories

Resources