[PyKDE] What little detail am I missing?

Andreas Pakulat apaku at gmx.de
Thu Feb 9 14:35:39 GMT 2006


On 09.02.06 14:40:55, Tina Isaksen wrote:
> Ok, an even simpler thing: Take the innput and print it in a terminal. And I 
> can't even do that so I must be missing something so basic that it's probably 
> redicilous. I have read examples, webpages etc and I just don't get it!!! :(

Did you check Python docs? Because your problem simply is a lack of
understanding how python works.

> My program named "enkeltestMain"
> 
> from qt import *
> from  enkeltest import *
> import sys
> 
> class click(enkelTest):
>    def __init__(self):
>        test = innput

Is innput defined in enkeltest.py? If not this won't work.

>        return test
> def prog():
>    print test

Here you access the variable "test" which is not defined anywhere.
Especiall prog() is global function, it's not in the scope of the click
class. I guess you want it to be in that scope, please be carefull with
indentation as that are the braces and curls in Python. So if you use
this:

class click(enkelTest):
  def __init__(self):
    enkelTest.__init__(self)
    self.test = innput
  def prog(self):
    print self.test

click would be a class that is an enkelTest but has a new function and a
new instance variable, provided that innput is a global variable.

>    app = QApplication(sys.argv)
>    f = enkelTest()
>    f.show()

Now do you want to instantiate your enkelTest class or your click class?
If the latter than change this to f = click().

With the fixed click class above f.show() and f.prog() will work as
expected.

> -----------------------------------------------------------------------------------
> 
> My "enkeltest.ui.h"

Not sure if those are working with PyQt3. I never used PyQt3.

> void enkelTest::click()
> {
> innput=self.lineEdit1.text().toInt()
> return innput
> }

You're mixing C++ and Python here, not good.

> -----------------------------------------------------------------------------------
> 
> I run pyuic enkeltest.ui > enkeltest.py
> 
> Errormessage when trying to run "enkeltestMain":
> The debugged program raised the exception unhandled NameError
> "global name 'test' is not defined"

see above the name "test" and the name "innput" are both not defined in
the global namespace. This has nothing to do with PyQt or Qt, that's
basic Python. There are good Python introductions on python.org.

Andreas

-- 
You have a deep appreciation of the arts and music.




More information about the PyQt mailing list