comboBox: sobald ich in ihr etwas auswähle "Fehler"
Verfasst: Mittwoch 8. November 2017, 10:47
Hi ich bin noch am anfang und lerne gerade erst Python und Qt. Mein problem ist die comboBox erzeugt immer einen fehler nach dem auswählen eines Objektes in der Gui.
Der Fehler:
Traceback (most recent call last):
File "/home/pi/pyqt5.py", line 48, in choosen
for count in range(self.box.count()):
AttributeError: 'Fenster' object has no attribute 'box'
Mein Code:
Der Fehler:
Traceback (most recent call last):
File "/home/pi/pyqt5.py", line 48, in choosen
for count in range(self.box.count()):
AttributeError: 'Fenster' object has no attribute 'box'
Mein Code:
Code: Alles auswählen
import sys
from PyQt4.QtCore import*
from PyQt4.QtGui import*
from PyQt4.uic import*
class Fenster(QWidget):
def __init__(self):
super().__init__()
self.initMe()
def initMe(self):
button = QRadioButton("X",self)
button2 = QRadioButton("Y",self)
button3 = QRadioButton("Z",self)
box = QComboBox(self)
box.addItem("Motor1")
box.addItem("Motor2")
box.addItem("Motor3")
box.addItem("C")
button.move(50,50)
button2.move(50,200)
button3.move(200,200)
button.clicked.connect(self.gedrueckt1)
button2.clicked.connect(self.gedrueckt2)
button3.clicked.connect(self.gedrueckt3)
box.currentIndexChanged.connect(self.choosen)
self.setGeometry(50,50,800,480)
self.setWindowTitle("H")
self.show()
print (box.count)
def gedrueckt1(self):
print("X")
def gedrueckt2(self):
print("y")
def gedrueckt3(self):
print("Z")
def choosen(self,i):
print ("Items in the list are :")
for count in range(self.box.count()):
print (box.itemText(count))
print ("Current index",i,"selection changed ",self.box.currentText())
app= QApplication(sys.argv)
w= Fenster()
sys.exit(app.exec_())