tags:

views:

203

answers:

1

I have a top level widget that is producing a syntax error in python. raise() on line 15. This is using the python Qt bindings. I know that raise is a python reserved word. I am looking for how to call the Qt "raise()" function with the python bindings.

#!/usr/bin/python

# simple.py

import sys 
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)

widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('simple')
widget.show()
widget.activateWindow ()
widget.raise() 

sys.exit(app.exec_())
+3  A: 

"raise" is a keyword (reserved word) in Python. So, you can't use it. And PyQt4 certainly doesn't use it as you think, because, well, it's a keyword, so no extension can. It's like you can't use "from" for a variable name (pet peeve: Python doesn't have variables, but I digress...)

As a hint, it's also highlighted by the syntax highlighter of SO.

Just a bit of interactive pythoneering... and it's raise_. Yep, with an underscore tacked on at the end. Pretty standard method when you have a keyword as a method/function.

jae
I need to call the "raise()" function to raise the window the fron top of the stack. The question is really - what did they make the raise() function call - since it is a reserved word in pyton?
Philip Schlump
And I'm not even a Qt person, I know GTK+ quite a bit better, and I don't even know GTK+ all that well (anymore). ;-)
jae
Oh, and sorry for not reading you question thoroughly.
jae
To make it absolutely clear, you should call `widget.raise_()` (like you have done for `app.exec_()`). Both exec and raise are reserved words in Python, but they are not in C++, which is the language Qt was designed for.
Lukáš Lalinský