<html><body><div style="color:#000; background-color:#fff; font-family:tahoma, new york, times, serif;font-size:10pt"><div>without the prefix 'self', tension is not an attribute of class, so it complaints this. you try replacing it with below :</div><div><br></div><div><span class="Apple-style-span" style="font-size: 16px; ">...</span></div><div><span class="Apple-style-span" style="font-size: 16px; ">self.tension = QDoubleSpinBox()</span><br></div><div><span class="Apple-style-span" style="font-size: 16px; ">self.tension.valueChanged.connect(self.voltage)</span><br style="font-size: 16px; "><span class="Apple-style-span" style="font-size: 16px; ">self.tension.setRange(0,100)</span></div><div><span class="Apple-style-span" style="font-size: 16px; ">...</span></div> <div style="font-size: 10pt; font-family: tahoma, 'new york', times, serif; "> <div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "> <font size="2"
face="Arial"> <hr size="1"> <b><span style="font-weight:bold;">From:</span></b> Fabien Lafont <lafont.fabien@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> pyqt@riverbankcomputing.com <br> <b><span style="font-weight: bold;">Sent:</span></b> Wednesday, January 4, 2012 5:26 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> [PyQt] How to extract the value of a Qspinbox?<br> </font> <br>
I'm trying to extract the value of an QDoubleSpinBox but I can't<br>understand why it does not work. It returns:<br><br>levoltage = self.tension.value()<br>AttributeError: 'ApplicationWindow' object has no attribute 'tension'<br><br>Do you have any idea why? I'm just starting to learn PyQt :)<br><br>My code:<br><br><br><br><br>from visa import *<br>from pylab import *<br>import sys<br>from PyQt4 import QtGui<br>import numpy as np<br>import random<br>import ImageGrab<br>from PyQt4 import QtCore, QtGui<br>from matplotlib.figure import Figure<br>from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas<br>from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg<br>as NavigationToolbar<br>from PyQt4.QtGui import (QApplication, QLabel, QLineEdit, QSpinBox,<br>QDoubleSpinBox,<br> QVBoxLayout, QDial, QGridLayout, QComboBox, QPushButton)<br>from PyQt4.QtCore import (QObject, Qt, SIGNAL,
SLOT)<br><br>class ApplicationWindow(QtGui.QMainWindow):<br> """Example main window"""<br> def __init__(self):<br> global lechemin<br> # initialization of Qt MainWindow widget<br> QtGui.QMainWindow.__init__(self)<br> # set window title<br> self.setWindowTitle("QHE manip")<br> # instantiate a widget, it will be the main one<br> self.main_widget = QtGui.QWidget(self)<br> # create a vertical box layout widget<br> vbl = QtGui.QVBoxLayout(self.main_widget)<br><br> # instantiate our Matplotlib canvas
widget<br><br><br>#===============================================================================<br><br>#===============================================================================<br><br> chemin = QLineEdit("C://testfab.jpg")<br># chemin.returnPressed.connect(self.sauvegarde)<br> self.connect(chemin, SIGNAL("returnPressed()"),<br> self.sauvegarde)<br># lechemin = unicode(chemin.text())<br>#===============================================================================<br><br> tension = QDoubleSpinBox()<br> tension.valueChanged.connect(self.voltage)<br> tension.setRange(0,100)<br><br><br>#===============================================================================<br><br>
vbl.addWidget(chemin)<br> vbl.addWidget(tension)<br><br> # set the focus on the main widget<br> self.main_widget.setFocus()<br> # set the central widget of MainWindow to main_widget<br> self.setCentralWidget(self.main_widget)<br><br> def sauvegarde(self) :<br> global lechemin<br> lechemin = unicode(self.chemin.text())<br><br> print lechemin<br><br> def voltage(self) :<br> global levoltage<br> levoltage = self.tension.value()<br><br>qApp = QtGui.QApplication(sys.argv)<br># instantiate the ApplicationWindow widget<br>aw = ApplicationWindow()<br># show the widget<br>aw.show()<br># start the Qt main loop execution, exiting from this script<br># with the
same return code of Qt application<br>sys.exit(qApp.exec_())<br>_______________________________________________<br>PyQt mailing list <a ymailto="mailto:PyQt@riverbankcomputing.com" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>http://www.riverbankcomputing.com/mailman/listinfo/pyqt<br><br><br> </div> </div> </div></body></html>