Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED}Making noises when buttons get pushed.
I want to get a button to make a noise when it gets pushed so I know it's sent an email, someone previously told me I need Phonon, but I can't find it anywhere, is there any other way of doing it that doesn't require additional modules?
This is the script I've got so far
from PyQt4 import QtGui, QtCore
from email.mime.text import MIMEText
self.button = QtGui.QPushButton('', self)
layout = QtGui.QVBoxLayout(self)
def handleButton(self): fp = open('Firetruck.txt', 'r') msg = MIMEText(fp.read()) fp.close() msg['Subject'] = 'Subject' msg['From'] = 'firstname.lastname@example.org' msg['To'] = 'email@example.com' s = smtplib.SMTP('BHS-MAIL') s.send_message(msg)
if name == 'main':
import sys app = QtGui.QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
I'm assuming the code for the sound goes under
[code] def handleButton(self): [/code]
That's in basic sounds the PC buzzer or other system used device. If you want specific sounds to be played a bit more work is needed.
Yeah that'd be fine :D
What do I need to import to get that to work?
Because I'm just getting invalid syntax and it's pointing to the first ":"
(not tested! But something like this)
// source file:
Because it's a static function of QApplication you don't need an object to be created or to use the qApp pointer. Just don't forget to include the QApplication module.
Think that this should work.
Ah I just found this - http://docs.python.org/2/library/winsound.html
Seems to work c:
Hmm, tried the beep() function here, but no sound on my laptop, so there might be an issue with it. (using Qt5.0.1 btw). It is only stated that it's not available on Embedded Linux.
jazzycamel last edited by
If fall you want is a beep then just use:
[quote author="swilliams2" date="1369304282"]Because I'm just getting invalid syntax and it's pointing to the first ":"[/quote]
This is because the example (QApplication::beep()) is for c++ and you're using Python.