开发者

Getting Started with PyQt [duplicate]

This question already has answers here: Getting Python error "from: can't read /var/mail/Bio" (7 answers) Closed 7 months ago.

I'm testing out some of the examples in Rapid GUI Programming with Python and Qt, but running into a stumbling block here or where. When I copied to following exercise (verbatim, from the book):

import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QApplication(sys.argv)

try:
   开发者_JAVA百科 due = QTime.currentTime()
    message = "Alert!"

    if len(sys.argv) < 2:
        raise ValueError

    hours, mins = sys.argv[1].split(":")
    due = QTime(int(hours), int(mins))

    if not due.isValid():
        raise ValueError
    if len(sys.argv) > 2:
        message = " ".join(sys.argv[2:])

except ValueError:
    message = "Usage: alert.pyw HH:MM [optional message*]" # 24hr Clock

while QTime.currentTime() < due:
    time.sleep(20) # 20 seconds

label = QLabel("<font color=red size=72><b>" + message + "</b></font>")

label.setWindowFlags(Qt.SplashScreen)
label.show()

QTimer.singleShot(60000, app.quit) # 1 minute

app.exec_()

I get the following error:

andy@ASUSix:~/Documents/Programming/Python/PyQt$ from: can't read /var/mail/PyQt4.QtCore
from: can't read /var/mail/PyQt4.QtGui
./alert.pyw: line 6: syntax error near unexpected token `('
./alert.pyw: line 6: `app = QApplication(sys.argv)

What's going wrong here? Is my PATH set up incorrectly?


You probably forgot to add a shebang to your script, to tell your shell to actually run it with the Python interpreter. Try adding

#!/usr/bin/python

as the first line in your script, provided that's where your Python interpreter is installed. You might want to try

which python

in case you're not sure.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜