I got a problem with python schedule - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I got a problem with python schedule (/thread-12985.html) |
I got a problem with python schedule - darktitan - Sep-22-2018 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. So what am i doing wrong? Here is my code. 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_()) RE: I got a problem with python schedule - stullis - Sep-22-2018 So, the traceback shows that the method call on line 29 ultimately results in an error because a string has been passed instead of an integer. From what I see, the suspect variable you're passing in is "sekunderValue" which is set on line 26: sekunderValue = self.sekunder.text()The method .text() suggests to me that it returns a string. If that is intended to be an integer, you need to do this instead for the ok_handler method: def ok_handler(self): sekunderValue = int(self.sekunder.text()) print(sekunderValue) schedule.every(sekunderValue).seconds.do(self.job) while 1: schedule.run_pending() time.sleep(1) RE: I got a problem with python schedule - darktitan - Sep-22-2018 Thank you |