���P���]
�����܌������n�̸��dȤ
Python��λ�C�_�l(f��)�̳�

��105С��(ji��)����9495�ˌW�^

Python��λ�C�_�l(f��)QTimer ���r���ؼ�
�l(f��)���r�g:2024-11-20 09:59 [ ��Ҫ�ԌW�W(w��ng)ԭ��(chu��ng) ] �l(f��)����: �옷СŮ ��x: 294

'''

���캯��(sh��)��

QTimer(parent: QObject = None): ��(chu��ng)��һ�� QTimer ���󣬿�ָ��������
���ԣ�
interval: �@ȡ���O�ö��r���ĕr�g�g�����Ժ�����λ����
isActive: �z�鶨�r���Ƿ������\�С�
������
start(interval: int = 0): ���Ӷ��r������ָ���r�g�g������δָ���tʹ��֮ǰ�O�õ��g������
stop(): ֹͣ���r����
setInterval(interval: int): �O�ö��r���ĕr�g�g����
setSingleShot(bool)�O�ö��r���Ƿ�H�|�l(f��)һ����
singleShot(): ��(zh��)��һ��
��̖��
timeout: �����r�����r�r�l(f��)�����̖��
'''

from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(600,400)
        self.setWindowTitle("QTimer���r���ؼ�")

        self.label = QLabel(self)
        self.label.setGeometry(30,30,30,30)
        self.label.setStyleSheet("background-color:red")

        self.btn_start = QPushButton("����",self)
        self.btn_stop = QPushButton("ֹͣ",self)

        self.btn_start.move(30,300)
        self.btn_stop.move(150,300)

        self.timer = QTimer(self)
        # self.timer.setInterval(100)
        self.timer.timeout.connect(self.on_timer_slot)
        # self.timer.setSingleShot(True)
        QTimer.singleShot(2000,self.label,self.change_label_color)

        self.num =0

        #slot
        self.btn_start.clicked.connect(self.on_btn_start_click)
        self.btn_stop.clicked.connect(self.on_btn_stop_click)

    def change_label_color(self):
        self.label.setStyleSheet("background-color:green")

    def on_btn_start_click(self):
        if self.timer.isActive():
            return
        self.timer.start(500)

    def on_btn_stop_click(self):
        if self.timer.isActive():
            self.timer.stop()

    def on_timer_slot(self):
        print("�ұ���(zh��)����")
        self.label.move(30+self.num,30)
        self.num+=10
        if self.num>self.width():self.num =0








if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec())

Python��λ�C�_�l(f��)�̳�
��Ҫ�ԌW�W(w��ng)�̳� ��80 Ԫ
�M��ُ�I
�����uՓ
���ӱ���
�������A���񹲺͇��ĸ�헵��·�Ҏ(gu��)��
�Г��������О�����µķ���؟����
��վ�Йౣ����h���Р��h�uՓ��
���c���uՓ���������ѽ�(j��ng)��x������
�����l����
V
�ػݳ�ֵ
“(li��n)ϵ�ͷ�
APP���d
�ٷ�΢��
����픲�
���P���]
�����܌������n�̸��dȤ
Python��λ�C�_�l(f��)�̳�

��105С��(ji��)����9495�ˌW�^

����x��:
��X�k�� ƽ���OӋ �҃�(n��i)�OӋ �����OӋ �Cе�OӋ ���I(y��)�Ԅӻ� Ӱҕ�Ӯ� �����_�l(f��) �W(w��ng)��OӋ ��Ӌ�n�� �dȤ���L AIGC