[PyQt] Shortening multiple widget initializations to one line
samjnaa at gmail.com
Mon Dec 10 16:47:16 GMT 2012
Hello -- thanks all for your kind replies. The ideas for multiple
creation are all useful. One more point below:
On Mon, Dec 10, 2012 at 9:49 PM, Matt Newell <newellm at blur.com> wrote:
>> 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):
>> AttributeError: 'MainWindow' object has no attribute 'p1xSpin'
> Probably some simple error here causing the line to try to get the attribute
> instead of set it.
Adding parantheses around the list corrected it. I forgot that only
when there is an enclosing parantheses or bracket (or with explicit \
like in C) will multi-line commands be recognized.
More information about the PyQt