<html><body><div style="color:#000; background-color:#fff; font-family:tahoma, new york, times, serif;font-size:10pt"><div>what about <i><b>vbl.addWidget(self.tension)</b></i> ?</div><div><br></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> Tayfun Kayhan <tayfun92_kayhan@yahoo.com> <br><b><span style="font-weight: bold;">Cc:</span></b> "pyqt@riverbankcomputing.com" <pyqt@riverbankcomputing.com> <br> <b><span style="font-weight: bold;">Sent:</span></b> Wednesday, January 4, 2012 6:04 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [PyQt] How to extract the value of a Qspinbox?<br> </font> <br>
Sorry, I should say it before but I've alreadt tryied this method:<br><br>it returns:<br><br>vbl.addWidget(tension)<br>NameError: global name 'tension' is not defined<br><br><br><br>2012/1/4 Tayfun Kayhan <<a ymailto="mailto:tayfun92_kayhan@yahoo.com" href="mailto:tayfun92_kayhan@yahoo.com">tayfun92_kayhan@yahoo.com</a>>:<br>> without the prefix 'self', tension is not an attribute of class, so it<br>> complaints this. you try replacing it with below :<br>><br>> ...<br>> self.tension = QDoubleSpinBox()<br>> self.tension.valueChanged.connect(self.voltage)<br>> self.tension.setRange(0,100)<br>> ...<br>> ________________________________<br>> From: Fabien Lafont <<a ymailto="mailto:lafont.fabien@gmail.com" href="mailto:lafont.fabien@gmail.com">lafont.fabien@gmail.com</a>><br>> To: <a ymailto="mailto:pyqt@riverbankcomputing.com" href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a><br>> Sent:
Wednesday, January 4, 2012 5:26 PM<br>> Subject: [PyQt] How to extract the value of a Qspinbox?<br>><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<br>> 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><br><br> </div> </div> </div></body></html>