Try answering these questions to test your knowledge from this chapter:
- Create code to call the self.every_ten_seconds() method every 10 seconds.
- The following code uses QTimer incorrectly. Can you fix it?
timer = qtc.QTimer()
timer.setSingleShot(True)
timer.setInterval(1000)
timer.start()
while timer.remainingTime():
sleep(.01)
run_delayed_command()
- You've created the following word-counting Worker class and want to move it to another thread to prevent large documents from slowing the GUI. But it's not working—what do you need to change about this class?
class Worker(qtc.QObject):
counted = qtc.pyqtSignal(int)
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
def count_words(self):
content = self.parent.textedit.toPlainText()
self.counted.emit(len(content.split...