In "Rapid GUI Programming with Python and Qt", the author gives this example in Chapter 4.
It seems to me that dial, spinbox, and layout would go out of scope. Why can we use dial instead of self.dial, spinbox instead of self.spinbox and layout instead of self.layout? Is this a good practice or is it better to use self. for all GUI elements?
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
dial = QDial()
dial.setNotchesVisible(True)
spinbox = QSpinBox()
layout = QHBoxLayout()
layout.addWidget(dial)
layout.addWidget(spinbox)
self.setLayout(layout)
self.connect(dial, SIGNAL("valueChanged(int)"),
spinbox.setValue)
self.connect(spinbox, SIGNAL("valueChanged(int)"),
dial.setValue)
self.setWindowTitle("Signals and Slots")
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()