Code cannot work in Eclipse

This is the place for queries that don't fit in any of the other categories.

Code cannot work in Eclipse

Postby dissidia.zac » Thu Jan 23, 2014 3:16 pm

Hi all, I just started on Python, so pardon me if I made any flukes in the way I wrote my coding, also at the fact that i do not know where to post my thread to
Anyway, I am using Ecplise Kepler, installed all the PyDev stuff with it, however, as I am trying to write out a simple program, I keep getting errors, resulting me unable to execute the program at all.

Code: Select all
from PyQt4 import QtGui
from PyQt4 import QtCore
import sys

class Form(QDialog):
    def __init__(self, parent = None):
        #super(Form,self).__init__(parent)
        testlabel = QLabel('Test01')
        testCombo = QComboBox('Combo Box')
        buttonBox = ButtonBox(QDialogButtonBox.Ok| QDialogButtonBox.Cancel)
       
        grid = QGridLayout()
        grid.addWidget(testlabel,0,0)
        grid.addWidget(testCombo, 0,1)
        grid.addWidget(buttonBox, 2,0,1,2)
        self.setLayout(grid)
       
def main():
   
    app = sys.argv
    form = Form()
    form.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()


In Eclipse, the QDialog, and all the wordings with the alphabet Q in it, are underlined in red, with the error message stating that it is not being defined and hence un-executable.
So either this means, I am writing it wayyyy wrong or there are some settings that I need to tweak in Eclipse for it to work?

Can someone help me?
Last edited by Mekire on Thu Jan 23, 2014 3:24 pm, edited 1 time in total.
Reason: First post lock.
dissidia.zac
 
Posts: 1
Joined: Thu Jan 23, 2014 3:03 pm

Re: Code cannot work in Eclipse

Postby metulburr » Thu Jan 23, 2014 7:30 pm

In Eclipse, the QDialog, and all the wordings with the alphabet Q in it, are underlined in red, with the error message stating that it is not being defined and hence un-executable.


You need to preceed QDialog, QLabel, etc. with QtGui the way you imported it.
Code: Select all
QtGui.QDialog


this is how you add a string
Code: Select all
        testCombo = QtGui.QComboBox()
        testCombo.addItem('Combo Box')


try this for testing
Code: Select all
import sys
from PyQt4 import QtGui

def main():
    app = QtGui.QApplication(sys.argv)
    w = QtGui.QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1331
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests