How would I go about playing an alarm sound in python?

python, tkinter

Solution

Assuming you're on Windows:

import winsound
winsound.PlaySound('alert.wav')

If you're on Linux (or Mac OS X I believe), you can either use pygame or call a Linux program (like mplayer) using `popen`. pygame example:

import pygame
pygame.init()

pygame.mixer.music.load("alert.ogg")
pygame.mixer.music.play()
pygame.event.wait()

Example using `popen`, which executes a command as if you were in the terminal:

from os import popen
cmd = "mplayer alert.ogg"
popen(cmd)

Problem

I have a clock I made and I'd like to make it an alarm clock.

Original source

Related problems