[PyQt] Shortening multiple widget initializations to one line

Shriramana Sharma samjnaa at gmail.com
Mon Dec 10 07:48:18 GMT 2012


Hi -- recently I was trying to shorten the following overly verbose
(IMO) lines to:

		self . p1xSpin = QSpinBox ()
		self . p1ySpin = QSpinBox ()
		self . c1xSpin = QSpinBox ()
		self . c1ySpin = QSpinBox ()
		self . c2xSpin = QSpinBox ()
		self . c2ySpin = QSpinBox ()
		self . p2xSpin = QSpinBox ()
		self . p2ySpin = QSpinBox ()

to:

		self . p1xSpin, self . p1ySpin, self . c1xSpin, self . c1ySpin,
		self . c2xSpin, self . c2ySpin, self . p2xSpin, self . p2ySpin,
		self . pHxSpin, self . pHySpin = ( QSpinBox () for i in range ( 10 ) )

but I got the error:

Traceback (most recent call last):
  File "./bezierview-cubic-interp.py", line 327, in <module>
    mainWindow = MainWindow ()
  File "./bezierview-cubic-interp.py", line 204, in __init__
    self . p1xSpin, self . p1ySpin, self . c1xSpin, self . c1ySpin,
AttributeError: 'MainWindow' object has no attribute 'p1xSpin'

Why is this, and is there any other method I can follow to shorten the
tortuous list of repetitive commands for initializing multiple
widgets?

Thanks!

-- 
Shriramana Sharma


More information about the PyQt mailing list