Python Forum
keeping track of pushbutton click
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?
Reply
#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.
Reply
#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.
Reply
#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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGUI] Pushbutton in ANSA Aishaf 2 2,566 Apr-27-2021, 11:22 AM
Last Post: Aishaf
  [PyQt] pushbutton with image issac_n 1 1,740 Jul-13-2020, 05:04 PM
Last Post: Knight18
  [PyQt] Add command to PushButton skaailet 1 1,659 Apr-11-2020, 01:46 PM
Last Post: deanhystad
  TypeError when using PushButton (PyQt5) lmsavk 1 6,674 Mar-03-2019, 04:21 PM
Last Post: Alfalfa
  pyqt clickable pushbutton problem pythonck 1 7,594 Dec-12-2017, 03:38 PM
Last Post: pythonck

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020