3 Replies - 1575 Views - Last Post: 03 January 2009 - 05:47 AM Rate Topic: -----

#1 jboy012000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 07-October 08

syntax error help

Post icon  Posted 02 January 2009 - 11:28 AM

Hi All,

I am learning tp use PyQt thats Python and QT4 to design software, so I started to write this little program to put a message on my screen at a certain time like a alarm clock, but I get a syntax error message at this point and I can't write anything else afterwords, please see my code so far below:-

>>> import sys
>>> import time
>>> from PyQt4.QtCore import *
>>> from PyQt4.QtGui import *
>>> app = QApplication(sys.argv)
>>> due = QTime.currentTime()
>>> message = "Alert!"
>>> if len(sys.argv) < 2:
raise ValueError
hours, mins = sys.argv[1].split(":")
SyntaxError: invalid syntax
>>>

In the Python IDLE it highlights the word "hours", can anyone tell me what I am doing wrong.

Thanks very much

Is This A Good Question/Topic? 0
  • +

Replies To: syntax error help

#2 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5846
  • View blog
  • Posts: 12,703
  • Joined: 16-October 07

Re: syntax error help

Posted 02 January 2009 - 12:08 PM

Looks fine. I couldn't reproduce the error:
>>> s = "12:34"
>>> hours, mins = s.split(":")
>>> hours
'12'
>>> mins
'34'
>>> 



However, if you're running through the interpreter, with the ">>>", the raise before the split should scream. It doesn't really make sense in context.
Was This Post Helpful? 0
  • +
  • -

#3 jboy012000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 07-October 08

Re: syntax error help

Posted 02 January 2009 - 12:30 PM

I see what you mean, I will have a play and let you know the outcome.

Thanks

John
Was This Post Helpful? 0
  • +
  • -

#4 jboy012000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 07-October 08

Re: syntax error help

Posted 03 January 2009 - 05:47 AM

Hi All,

I sorted my first problem by opening a new window within IDLE and wrote my code in there and yipee I finished my program, please see code below

import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QApplication(sys.argv)
due = QTime.currentTime()
message = "Alert!"
if len(sys.argv) < 2:
raise ValueError
hours, mins = sys.argv[1].slit(":")
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_()
QApplication.quit()

Now for my next problem, when I run the program it opens up in terminal as planned but runs then terminates so fast I don't get to see the outcome, is there a line of code I can add, so that my little message stays on screen longer, just so I can admire my achievements of my first Python program lol.

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1