'Python/PYQT5 'MainWindow' object has no attribute 'slideLeftMenu'
I do not understand why I receive this attribute error.
"AttributeError: 'MainWindow' object has no attribute 'slideLeftMenu'"
slideLeftMenu is defined immediately after its called "self.slideLeftMenu" by pushButton8
my ui_Interface.py is not included but can be if its helpful
main.py
############################
##IMPORTS
#############################
import sys
import os
from PySide2 import *
######################
##IMPORT GUI FILE
##########################
from ui_interface import *
##########################
#####################################
## MAIN WINDOW CLASS################
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.show
######################################################
## REMOVE WINDOWS TITLE BAR
#######################################################
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
######################################################
## MAIN BACKGROUND TRANSPARANCY
#######################################################
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
######################################################
## Shadow Effect Style
#######################################################
self.shadow = QGraphicsDropShadowEffect(self)
self.shadow.setBlurRadius(50)
self.shadow.setXOffset(0)
self.shadow.setYOffset(0)
self.shadow.setColor(QColor(0, 92, 157, 550))
######################################################
## SET SHADOW TO CENTRAL WIDGET
#######################################################
self.ui.centralwidget.setGraphicsEffect(self.shadow)
######################################################
## SET WindowsIcon & Title
#####################################################
self.setWindowIcon(QtGui.QIcon(":/Icons/add.svg"))
self.setWindowTitle("Dogma Indexer")
#######################################################
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
####################################################
####MINIMIZE GRIP
###################################################
QSizeGrip(self.ui.Size_Grip)
############################
## Close Window
####################################################
self.ui.pushButton.clicked.connect(lambda: self.
close())
## Minimize Window
####################################################
self.ui.pushButton_3.clicked.connect(lambda: self.
showMinimized())
self.show()
###################################################
## Restore/Maximize Window
###################################################
self.ui.pushButton_2.clicked.connect(lambda: self.
restore_or_maximize_window())
###################################################
#Hidden Menu Toggle
#################################################
self.ui.pushButton_8.clicked.connect(lambda: self.slideLeftMenu())
####################################################################
######## Slide Function
####################################################################
def slideLeftMenu(self):
### Get Menu Width
width = self.ui.Side_menu_Container.Width()
### If Minimized
if width == 0:
# Expand Menu
newWidth = 200
#if maximized
else:
#Restore menu
newWidth = 0
##############################
## Move window function
################################################### \\\\\\\ FIX LATER
#def moveWindow(e):
# if e.buttons() == Qt.LeftButton:
# self.move(self.pos() + e.globalPos() - self.clickPosition)
# self.clickPosition = e.globalPos()
# e.accept()
#self.ui.header_frame.mouseMoveEvent = moveWindow
#self.show()
#
## EXECUTE APP
##########################################
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
##########################################
Solution 1:[1]
Is the function defined under the __init__ function? They should both be under the class:
class MyClass:
def __init__(self):
pass
def my_func(self):
pass
Also, you are calling the function (you put () after the function). try:
self.ui.pushButton_8.clicked.connect(self.slideLeftMenu)
Actually, when connecting signals you don't need to use lambda functions unless you need to pass arguments to the connected functions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
