한국어
파이썬
 

PyQt4 [PyQt4]스레드 및 ProgressBar 예제 코드

pjk 2014.08.26 17:37 조회 수 : 8236

K-20140826-633091.png

 

from PyQt4 import QtCore, QtGui
from time import sleep
import sys, os

class MyCustomWidget(QtGui.QWidget):

    def __init__(self, parent=None):
        super(MyCustomWidget, self).__init__(parent)
        layout = QtGui.QVBoxLayout(self)

        # Create a progress bar and a button and add them to the main layout
        self.progressBar = QtGui.QProgressBar(self)
        self.progressBar.setRange(0,1)
        layout.addWidget(self.progressBar)
        button = QtGui.QPushButton("Start", self)
        layout.addWidget(button)      

        button.clicked.connect(self.onStart)

        self.myLongTask = TaskThread()
        self.myLongTask.taskFinished.connect(self.onFinished)

    def onStart(self): 
        self.progressBar.setRange(0,0)
        self.myLongTask.start()

    def onFinished(self):
        # Stop the pulsation
        self.progressBar.setRange(0,1)
        self.progressBar.setValue(1)


class TaskThread(QtCore.QThread):
    taskFinished = QtCore.pyqtSignal()
    def run(self):
        print "hello world"*100000
        self.taskFinished.emit() 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = MyCustomWidget()
    window.resize(640, 480)
    window.show()
    sys.exit(app.exec_())

 

 

 

번호 제목 글쓴이 날짜 조회 수
24 pybind11 에 대해서 makersweb 2023.07.23 1765
23 pydbus 바인딩을 이용하여 서비스 데몬과 D-Bus통신 file makersweb 2018.03.12 2044
22 우분투에 Python새 버전 설치 사용법 pjk 2015.02.10 3136
21 명령어 한줄로 내컴퓨터를 웹서버로 file 운영자 2019.01.25 3420
20 QML 및 Window 투명처리 file makersweb 2015.04.22 3982
19 다른 디렉터리의 파일(모듈) import 하기 pjk 2014.08.22 4691
18 How to Use Freeze pjk 2014.09.06 4706
17 Qt For Python(PySide2) QML 프로젝트 예제 file makersweb 2019.10.17 4749
16 print를 로그파일로 생성하기 (log출력 Redirection) makersweb 2015.03.18 5470
15 Python 문자열 관련 함수 레퍼런스 pjk 2014.08.29 6573
14 [PyQt4]마우스 클릭 이벤트 예제 코드 pjk 2014.08.26 6770
13 파이썬으로 작성된 소스를 py2exe을 이용하여 윈도우 응용프로그램 빌드시 콘솔창 숨기기 pjk 2014.07.29 7590
12 [PyQt4]개발 프로그램 버전표시 메세지 박스 pjk 2014.09.02 7639
11 Python + QML with PyQt4 makersweb 2015.03.24 7849
10 Python으로 작성된 프로그램을 윈도우응용프로그램(exe)으로 빌드하기 file pjk 2014.08.03 8090
9 [PyQt4]윈도우창에 별 찍기 예제 file pjk 2014.08.19 8130
8 [PyQt4]multiprocess 예제 코드 pjk 2014.08.26 8136
» [PyQt4]스레드 및 ProgressBar 예제 코드 file pjk 2014.08.26 8236
6 [Python]EXE또는 DLL파일의 버전정보를 알아내기위한 몇가지 방법 makersweb 2015.06.25 8630
5 Boost Python을 이용하여 python을 위한 C++ API 바인딩 [5] file makersweb 2017.01.08 9016