Python Forum
Button click doesnt work from my second class/layout in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Button click doesnt work from my second class/layout in Python
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - touchscreen, push the button like click the mouse John64 5 747 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Figure Gets Larger Every time I click a show button joshuagreineder 2 1,273 Aug-11-2022, 06:25 AM
Last Post: chinky
  [Kivy] Acces atributes from a button defined in a class inside the .kv Tomli 2 2,055 Jun-10-2021, 01:05 AM
Last Post: Tomli
  [Tkinter] Modify Class on Button Click KDog 4 3,907 May-11-2021, 08:43 PM
Last Post: KDog
  pyqt5 layout Nickd12 8 3,407 Jan-18-2021, 09:09 AM
Last Post: Axel_Erfurt
  [Tkinter] Button click problem using OOP JohnB 5 3,524 Oct-21-2020, 12:43 PM
Last Post: JohnB
  tkinter | Button color text on Click Maryan 2 3,317 Oct-09-2020, 08:56 PM
Last Post: Maryan
  Class function does not create command button Heyjoe 2 2,230 Aug-22-2020, 08:06 PM
Last Post: Heyjoe
  Closing window on button click not working kenwatts275 4 3,674 May-03-2020, 01:59 PM
Last Post: deanhystad
  Reset Button did not work ardvci 2 2,723 Mar-02-2020, 07:59 PM
Last Post: ardvci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020