如何在PyQt python窗口的开头调用函数?

2024-04-18 21:25:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在app/form/window启动时调用我的keypress_request()函数,但它没有被调用? 我有办法做到吗?在

import time
from PyQt5 import QtCore, QtGui, QtWidgets
from screenkeep import Ui_MainWindow
from keypress_m import perform_keypress
from multiprocessing import Process


class ScreenKeepProgram(Ui_MainWindow):
    def __init__(self, parent=None):
        super(ScreenKeepProgram, self).__init__(self)
        self.setupUi(self)

        # This below is the function I want to call
        # at the start of the program, with no success
        self.keypress_request()

    def keypress_action(self):
        while True:
            time.sleep(5)
            perform_keypress('o')

    def keypress_request(self):
        do_keypress = Process(target=self.keypress_action)
        do_keypress.daemon = True
        do_keypress.start()

Tags: thefromimportselfuitimeinitrequest