pyqt5 python3 양식 작성 및 데이터 실시간 업데이트 예

2063 단어
# code:utf-8
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
import time


class MyTable(QTableWidget):
    def __init__(self, parent=None):
        super(MyTable, self).__init__(parent)
        self.setWindowTitle("           ")  #       
        self.setWindowIcon(QIcon("ok.png"))  #     (     )
        self.resize(600, 200)  #       (    )
        self.setColumnCount(5)  #     
        self.setRowCount(5)  #     
        # self.setColumnWidth(0, 200)  #     (   ,   )
        # self.setRowHeight(0, 100)  #     (   ,   )
     
        column_name = [
            'ETH/BIC',
            'column1',
            'column2',
            'column3',
            'column4',
        ]
        self.setHorizontalHeaderLabels(column_name)  #      
        row_name = [
            'binance',
            'okex',
            'bitfinex',
            'bittrex',
            'bithumb',
        ]
        self.setVerticalHeaderLabels(row_name)  #      

    def update_item_data(self, data):
        """    """
        self.setItem(0, 0, QTableWidgetItem(data)) #       ( ,  )   


class UpdateData(QThread):
    """     """
    update_date = pyqtSignal(str)  # pyqt5   python3 str,  Qstring

    def run(self):
        cnt = 0
        while True:
            cnt += 1
            self.update_date.emit(str(cnt))  #     
            time.sleep(1)


if __name__ == '__main__':
    #      
    app = QApplication(sys.argv)
    myTable = MyTable()
    #       
    update_data_thread = UpdateData()
    update_data_thread.update_date.connect(myTable.update_item_data)  #     
    update_data_thread.start()

    #        
    desktop = QApplication.desktop()  #     
    x = (desktop.width() - myTable.width()) // 2
    y = (desktop.height() - myTable.height()) // 2
    myTable.move(x, y)  #   

    #     
    myTable.show()
    app.exit(app.exec_())

좋은 웹페이지 즐겨찾기