Python Forum
keeping track of pushbutton click - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: keeping track of pushbutton click (/thread-2366.html)



keeping track of pushbutton click - iFunKtion - Mar-10-2017

Hi there,

Due to the slightly annoying thing about not being able to return a value from a method when a button is clicked, how do you keep track of button clicks. I have a simple message window, and the messages are downloaded into a list and I want to cycle through this list so usually, you could set up a simple while false loop and iterate through,  but I can't work out how you are supposed to do that with qt, if you have to call another method and can't pass variables back and forth

How is this done?


RE: keeping track of pushbutton click - Larz60+ - Mar-10-2017

Not sure how it's done in Qt, but the button must create an event when clicked. That
event must to bound to a function that gets executed when the event is generated. In
tkinter, that is done by using a bind statement associated with the button, or through a
command attribute in the Buttons instance. I seem to recall an on_click attribute in qt that can be set in a similar manner.


RE: keeping track of pushbutton click - iFunKtion - Mar-13-2017

Yes, it's the same in Qt, the only problem is you can't pass any data to or from the function being called. My work around is to use Global variables, but I don't see this as a good way to do this especially as this is the only reason to use a global variable in the whole of the application.


RE: keeping track of pushbutton click - Larz60+ - Mar-13-2017

Are you coding from an editor, or using designer?
If from an editor, you should be able to add an argument by using a lambda statement.
I'll find an example (not in Qt, but should work the same)
and post it jast as soon as I do

Example:
b1 = tk.Button(self.f1, text="Page 1", command=lambda: self.show_page(self.page1), width=8, height=2)