I am trying to develop a gui with PySide and I wonder if there is a way to call a function in Python (QDate
) and run it in a specific date and time?
for example:
#run this function in everyday at 8:00 am.
def print_something():
print "Hello"
Here is a script adapted from Chapter 4 of Summerfield's PyQt book, his
alert.py
example. It is available free online here: http://www.informit.com/articles/article.aspx?p=1149122Basically you set a target
QDateTime
, and then you can trigger whatever callable you want by comparing the target tocurrentQDateTime
:This one has a QLabel pop up at the day and time you want, but that is arbitrary. You could have it do anything you want. If you want it to run every day at the same time, you would have to modify it appropriately, but this should be enough to get you started using
QDateTime
to trigger events.Note if you are working in Windows and you want to run it in the background, without a command window showing on your screen, then follow the advice here:
How can I hide the console window in a PyQt app running on Windows?
Namely, save the program with
.pyw
extension and make sure it is running withpythonw.exe
, notpython.exe
.