Sep-22-2018, 03:51 AM
Hi im trying to make an time triggered event with schedule where i can inpute a time and then activate the clock after a couple of seconds something would happen but my code is giving me an error.
Here is my code.
Error:Traceback (most recent call last):
File "C:\Users\xzenon\Desktop\timmer\time2.py", line 29, in ok_handler
schedule.every(sekunderValue).seconds.do(self.job)
File "C:\Users\xzenon\AppData\Local\Programs\Python\Python37-32\lib\site-packages\schedule\__init__.py", line 393, in do
self._schedule_next_run()
File "C:\Users\xzenon\AppData\Local\Programs\Python\Python37-32\lib\site-packages\schedule\__init__.py", line 428, in _schedule_next_run
self.period = datetime.timedelta(**{self.unit: interval})
TypeError: unsupported type for timedelta seconds component: str
So what am i doing wrong? Here is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import sys import schedule from PySide2.QtUiTools import QUiLoader from PySide2.QtWidgets import QApplication, QPushButton, QLineEdit from PySide2.QtCore import QFile, QObject class Form(QObject): def __init__( self , ui_file, parent = None ): super (Form, self ).__init__(parent) ui_file = QFile(ui_file) ui_file. open (QFile.ReadOnly) loader = QUiLoader() self .window = loader.load(ui_file) ui_file.close() self .sekunder = self .window.findChild(QLineEdit, 'sekunder' ) btn = self .window.findChild(QPushButton, 'pushButton' ) btn.clicked.connect( self .ok_handler) self .window.show() def ok_handler( self ): sekunderValue = self .sekunder.text() print (sekunderValue) schedule.every(sekunderValue).seconds.do( self .job) while 1 : schedule.run_pending() time.sleep( 1 ) def job( self ): print ( "I'm working..." ) if __name__ = = '__main__' : app = QApplication(sys.argv) form = Form( 'timmer.ui' ) sys.exit(app.exec_()) |