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