What to do to avoid error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: What to do to avoid error (/thread-1844.html) |
What to do to avoid error - California - Jan-29-2017 Hello, I am getting an error when calling function from apps_5 modul into main. I need those 3 modules, becouse a lot of code will be inside. Any help would be appreciatted. An error: main:# python 2.7.9 from PyQt4 import QtCore, QtGui import gui_5 from apps_5 import print_situation import sys if __name__ == "__main__": app = QtGui.QApplication(sys.argv) gui_master = gui_5.QtGui.QWidget() master = gui_5.Ui_Form() master.setupUi(gui_master) master.checkBox.clicked.connect(print_situation) gui_master.show() sys.exit(app.exec_())gui modul: from PyQt4 import QtCore, QtGui import apps_5 #from apps_2 import my_app try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) class Ui_Form(object): def setupUi(self, Form): Form.setObjectName(_fromUtf8("Form")) Form.resize(400, 300) self.checkBox = QtGui.QCheckBox(Form) self.checkBox.setGeometry(QtCore.QRect(200, 150, 100, 26)) self.checkBox.setObjectName(_fromUtf8("checkBox")) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): Form.setWindowTitle(_translate("Form", "Form", None)) self.checkBox.setText(_translate("Form", "CheckBox", None)) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) Form = QtGui.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_())apps_5 modul: # python 2.7.9 from PyQt4 import QtCore, QtGui import gui_5 def print_situation(self): self.checkBox = QtGui.QCheckBox(self) if self.checkBox.checkState() == QtCore.Qt.Checked: print "Checked" else: print "Unchecked" RE: What to do to avoid error - nilamo - Feb-03-2017 (Jan-29-2017, 11:08 AM)California Wrote: Sounds like print_situation() is being called with different parameters than you expect it is. For example, what do you think "self" means here? Because whatever you think it is, it's apparently a True/False. My suggestion would be to either 1) change the function to have *args and then print them out so you see what it's actually getting called with, or 2) look up the docs for what button.click.connect does. RE: What to do to avoid error - California - Feb-03-2017 Great improoving with your advice No.1. No error message this time with printed "Unchecked" when checkbox is checked and again "Unchecked" when checkbox is unchecked. Button will be checke tomorrow, report is comming. Thank you verry much for your help. Regards, Vlado |