2016-04-11 35 views

答えて

0

は、彼のalert.py例サマーのPyQtはブックの第4章から適応スクリプトです。ここは、オンラインで無料提供されています: http://www.informit.com/articles/article.aspx?p=1149122

基本的にあなたがターゲットQDateTimeを設定し、あなたがcurrentQDateTimeにターゲットを比較することによって、あなたが望む呼び出し可能なものは何でもトリガすることができます。

from PySide import QtCore, QtGui 
import sys 
import time 

#Prepare alarm 
alarmMessage = "Wake up, sleepyhead!" 
year = 2016 
month = 4 
day = 23 
hour = 12 
minute = 40  
alarmDateTime = QtCore.QDateTime(int(year), int(month), int(day), int(hour), int(minute), int(0)) 
#Wait for alarm to trigger at appropriate time (check every 5 seconds) 
while QtCore.QDateTime.currentDateTime() < alarmDateTime: 
    time.sleep(5) 

#Once alarm is triggered, create and show QLabel, and then exit application 
qtApp = QtGui.QApplication(sys.argv) 
label = QtGui.QLabel(alarmMessage) 
label.setStyleSheet("QLabel { color: rgb(255, 0, 0); font-weight: bold; font-size: 25px; \ 
        background-color: rgb(0,0,0); border: 5px solid rgba(0 , 255, 0, 200)}") 
label.setWindowFlags(QtCore.Qt.SplashScreen | QtCore.Qt.WindowStaysOnTopHint) 
label.show() 
waitTime = 10000 #in milliseconds 
QtCore.QTimer.singleShot(waitTime, qtApp.quit) 
sys.exit(qtApp.exec_()) 

この1つはQLabelポップアップしていますあなたが望む日と時間に、それは恣意的です。あなたはそれがあなたが望む何でもすることができます。毎日同じ日に実行したい場合は、適切に修正する必要がありますが、これはイベントをトリガーするのにQDateTimeを使い始めるのに十分なはずです。

注Windowsで作業しているし、あなたはここでアドバイスに従う、画面上の表示コマンドウィンドウなしに、バックグラウンドで実行する場合:プログラムを保存、すなわち

How can I hide the console window in a PyQt app running on Windows?

.pywの拡張子を使用し、ではなく、python.exeで実行されていることを確認してください。

関連する問題