I'm working on Window 10,PyCharm-Python 3.5.2
What I was trying to do: If PB1(push button 1) clicked, open a new window.
Problem: I get an error
self.PB1.clicked.connect(self.Soft_Memory())
TypeError: argument 1 has unexpected type 'NoneType'
Since I defined Soft_Memory(), I don't see why Soft_Memory() is NoneType.
Though on the editor '.connect' gets highlighted and says cannot find reference 'connect' in 'function'
Codes are below. I've erased some part of the code so that its better to see. If anyone need the full code please comment.
SM.py
class SM_Window(QMainWindow, QWidget):
def __init__(self, parent=None):
super().__init__()
self.initU()
def initU(self):
self.setWindowTitle("SM_Window")
self.setGeometry(10, 30, 850, 850)
UI.py
import SM
class MainWindow(QMainWindow, QWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.initUI()
def Soft_Memory(self):
self.SF = SM.SM_Window()
self.SF.show()
def Buttons(self):
#Button for SF
self.PB1 = QPushButton("POP", self)
self.PB1.setToolTip("POPOPOPOPOPOP")
self.PB1.move(100, 100)
def Signal_to_Slot(self):
self.PB1.clicked.connect(self.Soft_Memory())
def initUI(self):
self.setWindowTitle("UI")
self.setGeometry(850, 850, 850, 850)
self.Buttons()
self.Signal_to_Slot()
self.showMaximized()
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec())
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…