开发者

python qt raise syntax error

开发者 https://www.devze.com 2022-12-15 12:46 出处:网络
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 th

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_())


"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.

0

精彩评论

暂无评论...
验证码 换一张
取 消