Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 keeping track of pushbutton click
#1
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?
Quote
#2
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.
Quote
#3
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.
Quote
#4
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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  TypeError when using PushButton (PyQt5) lmsavk 1 495 Mar-03-2019, 04:21 PM
Last Post: Alfalfa
  pyqt clickable pushbutton problem pythonck 1 3,470 Dec-12-2017, 03:38 PM
Last Post: pythonck

Forum Jump:


Users browsing this thread: 1 Guest(s)