How to move class method out of gui modul
-
Smal change in function makes script running without an error but only "Unchecked" is printed out when radiobutton is checked or it is unchecked. How to fix this to have correct respond?
# python 2.7.9 from PyQt4 import QtCore, QtGui #from gui_1 import Ui_Form def print_situation(*args): radioButton = QtGui.QRadioButton() if radioButton.isChecked(): print "Checked" else: print "Unchecked"
-
Importing functions or classes is exactly the same process.
The thing that you seem to want to do is take apart class functions
Take a look at the 3rd example from the PyQt 5 designer introduction documentation.
Basically, you have your generated file from pyuic5, then you create your own class that will use the generated code. Finally a main.py where you will instantiate your custom widget(s) and start the application.
-
Hi
Wontdef print_situation(*args): radioButton = QtGui.QRadioButton() if radioButton.isChecked(): print "Checked" else: print "Unchecked"
radioButton = QtGui.QRadioButton()
create a new QRadioButtonEach time and its unchecked by default.
Hence it always says "Unchecked" ?
-
@mrjj you are right I suppose
@SGaist I tried to follow your point but ...
code:# python 2.7.9 from PyQt4 import QtCore, QtGui from PyQt4.QtGui import QCheckBox #from gui_5 import Ui_Form class My_app(QCheckBox): def __init__(self): super(My_app, self).__init__() # Set up the user interface from Designer. self.setupUi(self) self.checkBox = QtGui.QCheckBox(self) # Connect up the buttons. self.checkBox.clicked.connect(self.accept) def print_situation(self, *args): if self.checkBox.checkState() == QtCore.Qt.Checked: print "Checked" else: print "Unchecked"
error:
Traceback (most recent call last): File "/home/pi/Desktop/Qt4/Project/01/Test_Class/main_5.py", line 17, in <module> master.checkBox.clicked.connect(My_app.print_situation) AttributeError: 'function' object has no attribute '__pyqtSignature__'
-
Why are you deriving from a QCheckBox and then create a new checkbox in it ?
-
Would you be so kind to rewritte this code to loose error, because I am lost at the momment.
A lot of time was spent for this issue in last month and I didn't make any progress at all. -
I will take no respond as this issue is mission impossible.
Thanks for your help.Vlado
-
@California said in How to move class method out of gui modul:
mission impossible.
Well you seem to lack (some ?) understanding of classes in python.
https://www.tutorialspoint.com/python/python_classes_objects.htmI think all the issue comes from that. Using Qt does not change anything.
So maybe stop with Qt for a day. Try to use own objects like you want to with Qt.
If you do not know how to make instance of a class or how to use them as parameters etc then
its hard to split to extra files.Just saying. Im even bigger Beginner with python. :)
-
Thanks for this useffull link.