Unable to find cause of error

Post here if you need help with creating a Graphical User Interface in Python.

Unable to find cause of error

Postby salik89 » Sun Jan 26, 2014 1:57 pm

Hi all, I have this problem in which my execution keeps calling out an error, rendering me unable to execute my program at all.
My error message is, ''mainWindow' object has no attribute 'updateMenu'

But I tried to define it in the earlier part, still I am unable to get it to work.

Can someone tell me where I am wrong?

Code: Select all
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class mainWindow(QDialog):
    def __init__(self, parent=None):
        super(mainWindow, self).__init__(parent)
        self.updateMenu()

        self.setShowLbl = QLabel('Show Name')
        self.setShowTxt = QLineEdit()
        self.setShowBtn = QPushButton('Set Show')
   
        gridLayout01 = QGridLayout()
        gridLayout01.addWidget(self.setShowLbl,0,0)
        gridLayout01.addWidget(self.setShowTxt,0,1)
        gridLayout01.addWidget(self.setShowBtn,0,2)

        self.setLayout(gridLayout01)
        self.setWindowTitle("Set Shot")
       
        self.connect(self.setShowBtn, SIGNAL('clicked()'), self.updateMenu)

        def updateMenu(self):
            print('workin')

app = QApplication(sys.argv)
form = mainWindow()
form.show()
app.exec_()
salik89
 
Posts: 13
Joined: Mon Jan 20, 2014 4:36 pm

Re: Unable to find cause of error

Postby Mekire » Sun Jan 26, 2014 2:07 pm

Your function is indented inside your __init__:

Code: Select all
import sys

from PyQt4.QtCore import *
from PyQt4.QtGui import *


class mainWindow(QDialog):
    def __init__(self, parent=None):
        super(mainWindow, self).__init__(parent)
        self.updateMenu()
        self.setShowLbl = QLabel('Show Name')
        self.setShowTxt = QLineEdit()
        self.setShowBtn = QPushButton('Set Show')
        gridLayout01 = QGridLayout()
        gridLayout01.addWidget(self.setShowLbl,0,0)
        gridLayout01.addWidget(self.setShowTxt,0,1)
        gridLayout01.addWidget(self.setShowBtn,0,2)
        self.setLayout(gridLayout01)
        self.setWindowTitle("Set Shot")
        self.connect(self.setShowBtn, SIGNAL('clicked()'), self.updateMenu)

    def updateMenu(self):
        print('workin')

if __name__ == "__main__":
    app = QApplication(sys.argv)
    form = mainWindow()
    form.show()
    app.exec_()

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Unable to find cause of error

Postby salik89 » Sun Jan 26, 2014 2:19 pm

Thanks, Mek!
That is a noobie mistake :oops:

By the way could I ask if I am going to code a QCheckBox, is it necessary for me to write it out 'self.connect' code?
Or will it be better to define it?

Code: Select all
        self.connect(self.setTimeline, SIGNAL('clicked()'), self.updateMenu)

    def updateMenu(self):
        if self.setTimeline.isChecked() == True:
            print('workin')
        else:
            print('not working')
salik89
 
Posts: 13
Joined: Mon Jan 20, 2014 4:36 pm


Return to GUI

Who is online

Users browsing this forum: W3C [Linkcheck] and 1 guest