ich geb ja nicht auf, auch wenn ich manchmal etwas langsam bin
Da ich ja nur für mich etwas Spielkram machen möchte, kann ich mir ja auch eine GUI zusammenklicken. Da hab ich einen Test gemacht mit dem
Qt-Designer. Dann hab ich die .ui in .py umgewandelt und ein script erstellt, das mir die GUI einliest, da man in
der neuen .py ja nicht "rumfummeln" soll... ich weiss nicht genau, wie ich es erklären soll
Ich hab 3 Felder und 2 Buttons drin, in 2 der Felder sollen Werte eingetragen werden und dann ganz simpel automatisch
im 3. Feld zusammengezählt werden.
Ein Button leert die Felder und einer schliesst das "Programm".
Hier mal die umgewandelte GUI Datei
Code: Alles auswählen
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created: Sat Aug 31 13:53:09 2013
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(506, 437)
self.pushClose = QtGui.QPushButton(Dialog)
self.pushClose.setGeometry(QtCore.QRect(380, 390, 98, 27))
self.pushClose.setObjectName(_fromUtf8("pushClose"))
self.lineWert = QtGui.QLineEdit(Dialog)
self.lineWert.setGeometry(QtCore.QRect(110, 30, 113, 27))
self.lineWert.setObjectName(_fromUtf8("lineWert"))
self.lineWert_2 = QtGui.QLineEdit(Dialog)
self.lineWert_2.setGeometry(QtCore.QRect(110, 70, 113, 27))
self.lineWert_2.setObjectName(_fromUtf8("lineWert_2"))
self.lineWert_3 = QtGui.QLineEdit(Dialog)
self.lineWert_3.setGeometry(QtCore.QRect(110, 130, 113, 27))
self.lineWert_3.setObjectName(_fromUtf8("lineWert_3"))
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(20, 40, 66, 17))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(20, 80, 66, 17))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(20, 140, 66, 17))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.pushClear = QtGui.QPushButton(Dialog)
self.pushClear.setGeometry(QtCore.QRect(270, 80, 98, 27))
self.pushClear.setObjectName(_fromUtf8("pushClear"))
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.pushClose, QtCore.SIGNAL(_fromUtf8("clicked()")), Dialog.close)
QtCore.QObject.connect(self.pushClear, QtCore.SIGNAL(_fromUtf8("clicked()")), self.lineWert.clear)
QtCore.QObject.connect(self.pushClear, QtCore.SIGNAL(_fromUtf8("clicked()")), self.lineWert_2.clear)
QtCore.QObject.connect(self.pushClear, QtCore.SIGNAL(_fromUtf8("clicked()")), self.lineWert_3.clear)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.pushClose.setText(QtGui.QApplication.translate("Dialog", "Close", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Dialog", "Wert", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Dialog", "Wert_1", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("Dialog", "Wert_2", None, QtGui.QApplication.UnicodeUTF8))
self.pushClear.setText(QtGui.QApplication.translate("Dialog", "Clear", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
Code: Alles auswählen
from PyQt4 import QtCore,QtGui
import sys
import test
class testl(QtGui.QDialog,test.Ui_Dialog):
"""
testl is inherited from both QtGui.QDialog and test.Ui_Dialog
"""
def __init__(self,parent=None):
"""
Initialization of the class. Call the __init__ for the super classes
"""
super(testl,self).__init__(parent)
self.setupUi(self)
self.connectActions()
def main(self):
self.show()
def connectActions(self):
"""
Connect the user interface controls to the logic
"""
self.pushClose.clicked.connect(self.destroy)
def myprint(self):
self.lineWert.int(input(' '))
self.lineWert_2.int(input(''))
self.lineWert_3.int(lineWert + lineWert_2)
if __name__=='__main__':
app = QtGui.QApplication(sys.argv)
testl1 = testl()
testl1.main()
sys.exit(app.exec_())
und diese dann in lineWert_3 automatisch zusammengzählt werden.
Alternativ könnte ich auch einen weiteren Button einfügen, der das addieren veranlasst, aber auch da hänge ich... wobei mir das noch lieber wäre.
"Vorbereitet" hab ich das, siehe def myprint(self)
Ansonsten fehlt aktuell der Aufruf für myprint, ich hab heute soviel probiert, der ist mittlerweile abhanden gekommen...
LG
Holger