[PyKDE] Sending an argument to a function with a button click

Simon Edwards simon at simonzone.com
Mon Aug 4 23:46:00 BST 2003


Hello,

On Monday 04 August 2003 23:30, Peter Clark wrote:
> 	I've started dabbling with PyQt, but I'm a little confused as to how I can 
> pass an argument to a function with a button click. For instance, the 
> following doesn't work:
> (snip button code)
> 
> self.connect(self.button1, SIGNAL("clicked()"), 
self.printMessage("Testing"))
> 
> def printMessage(text):
>   print text

You can't. In this case printMessage()'s arguments must match clicked(), which 
in PyQt would be:

def printMessage(self): # don't forget the magic self.
  print "foo"

Why would you want to do this anyway? (You can use different slots for 
different buttons...)

cheers,

-- 
Simon Edwards             | Guarddog Firewall
simon at simonzone.com       | http://www.simonzone.com/software/
Nijmegen, The Netherlands | "ZooTV? You made the right choice."




More information about the PyQt mailing list