| | |
Alarm Question
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
As many people new to python i seem to have run into a bit of a snag with an alarm program i was making. I wanted to make something that would play a song (.wav) at a given time and would not stop unless you played a little game, guess the number from 1 to 100.
Now my program works when i run it in pythonwin through the interactive window, however when i try to run it though cmd the music doesn't play. here's what i came up with;
any help would be great.
Now my program works when i run it in pythonwin through the interactive window, however when i try to run it though cmd the music doesn't play. here's what i came up with;
Python Syntax (Toggle Plain Text)
from win32com.client import Dispatch #set up music player mp = Dispatch("WMPlayer.OCX") tune = mp.newMedia("Therock.wav") mp.currentPlaylist.appendItem(tune) import time import random #alarm clock print "Awesome Alarm Clock!" print "Awesome Alarm will go off at 8:00AM" not_exec = 1 while(not_exec): dt = list(time.localtime()) hour = dt[3] minute = dt[4] if hour == 8 and minute == 00: not_exec = 0 mp.controls.play() #turn off game print "Guess the number to stop the music" print "**********************************" guess = input("Guess > ") x = 0 rando = random.randint(1, 100) while x == 0: if guess > rando: guess = input("Nope too high try again ") mp.currentPlaylist.appendItem(tune) elif guess < rando: guess = input("Nope too low try again ") mp.currentPlaylist.appendItem(tune) else: print "Congrats, now try to stay awake" x=1 mp.controls.stop()
any help would be great.
•
•
Join Date: Dec 2006
Posts: 1,022
Reputation:
Solved Threads: 288
0
#2 24 Days Ago
That is usually a directory problem, i.e. it can't find something because it is not in the current directory. For this line, give it the absolute path name
tune = mp.newMedia("/complete/path/Therock.wav")
If that doesn't work, check that something is printed so you know the program was started. Finally, if you haven't found anything, use a try/except to catch error messages and see if anything is printed.
tune = mp.newMedia("/complete/path/Therock.wav")
If that doesn't work, check that something is printed so you know the program was started. Finally, if you haven't found anything, use a try/except to catch error messages and see if anything is printed.
Linux counter #99383
![]() |
Similar Threads
- WJQS.exe caught by Zone Alarm - Question (Viruses, Spyware and other Nasties)
Other Threads in the Python Forum
- Previous Thread: Rectangles in functions?
- Next Thread: Maze solving
| Thread Tools | Search this Thread |
address anydbm app bash beginner changecolor cipher class clear conversion coordinates corners curves definedlines development dictionary dynamic events examples excel feet file float format function generator getvalue gui handling homework images import input ip java keycontrol line linux list lists loan loop maintain matching maze millimeter mouse mysqldb number numbers output parsing path port prime programming projects py2exe pygame pymailer python queue random rational raw_input recursion recursive scrolledtext searchingfile shebang singleton slicenotation split string strings table tails terminal text thread threading time tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable variables vigenere web wx.wizard wxpython xlwt






