I am connecting widgets with event handlers in PyQt and trying to find the widget that was used. I learned to do this in wxPython:
button1 = wx.Button(self, -1, "Button 1")
button2 = wx.Button(self, -1, "Button 2")
button3 = wx.Button(self, -1, "Button 3")
button_group = (button1, button2, button3)
for entry in button_group:
entry.Bind(wx.EVT_BUTTON, self.onButton)
def onButton(self, event):
eventVal = event.GetEventObject()
labelVal = eventVal.GetLabel()
print "%s pressed" % labelVal
button1 = wx.Button(self, -1, "Button 1")
button2 = wx.Button(self, -1, "Button 2")
button3 = wx.Button(self, -1, "Button 3")
button_group = (button1, button2, button3)
for entry in button_group:
entry.Bind(wx.EVT_BUTTON, self.onButton)
def onButton(self, event):
eventVal = event.GetEventObject()
labelVal = eventVal.GetLabel()
print "%s pressed" % labelVal
To copy to clipboard, switch view to plain text mode
But I am having trouble figuring out how to do this with PyQt. This is the only way that I know how to catch events:
button_group = [button1, button2, button3]
for entry in button_group:
self.connect(entry, QtCore.SIGNAL('clicked()'), self.onButton)
def onButton(self):
"""
I do not know what to put here.
"""
pass
button1 = QtGui.QPushButton("Button 1")
button2 = QtGui.QPushButton("Button 2")
button3 = QtGui.QPushButton("Button 3")
button_group = [button1, button2, button3]
for entry in button_group:
self.connect(entry, QtCore.SIGNAL('clicked()'), self.onButton)
def onButton(self):
"""
I do not know what to put here.
"""
pass
To copy to clipboard, switch view to plain text mode
Bookmarks