Python Forum
Button click doesnt work from my second class/layout in Python - 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: Button click doesnt work from my second class/layout in Python (/thread-8288.html)



Button click doesnt work from my second class/layout in Python - imamideb - Feb-13-2018

I am using PyQt5 and I have designed 3 layouts.

Login
Dashboard
Settings

Login and Dashboard pages have individual class files. When I am trying to login, it gets logged in. After that, I am trying to click the settings button from my dashboard, but nothing happens. The layout doesnt change.

Whereas, if I individually run the dashboard file, clicking on the settings button works and the layout changes. I am like confused, why this is happening. Here is a piece of my code:

login.py:

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from login import Ui_loginWindow
from dashboard import Ui_dashboardWindow

class loginClass(Ui_loginWindow):
def __init__(self,dialog):
Ui_loginWindow.__init__(self)
self.setupUi(dialog)
self.loginBtn.clicked.connect(self.openDashboard)

def openDashboard(self):
self.newWindow = QtWidgets.QMainWindow()
self.dashboardWindow = Ui_dashboardWindow()
self.dashboardWindow.setupUi(self.newWindow)
loginWindow.hide() #works
self.newWindow.show() #works

if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
loginWindow = QtWidgets.QMainWindow()
var = loginClass(loginWindow)
loginWindow.show()
sys.exit(app.exec_())

dashboard.py:

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from dashboard import Ui_dashboardWindow
from settings import Ui_settingsWindow

class dashboardClass(Ui_dashboardWindow):
def __init__(self,dialog):
Ui_dashboardWindow.__init__(self)
self.setupUi(dialog)
self.settingsBtn.clicked.connect(self.openSettings)

def openSettings(self):
self.newWindow = QtWidgets.QMainWindow()
self.addWindow = Ui_addWindow()
self.addWindow.setupUi(self.newWindow)
dashboardWindow.hide() #doesnot work
self.newWindow.show() #doesnot work

if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
dashboardWindow = QtWidgets.QMainWindow()
var = dashboardClass(dashboardWindow)
dashboardWindow.show()
sys.exit(app.exec_())

[Image: Y4eaP.png]

The above image explains what I basically want to achieve.

Thanks

ok @Larz60+ but I am unable to edit my post now.