Python3でPyQt5を使用して、GUIを作成しております。
メインウインドウの起動に時間がかかるため、起動前にプログレスバーを設けようと思っておりますが、うまくいきません。
プロセスとして、
①メイン起動の前準備のため、データを読み取る・・・ex = window() に当たる
②ex.show()までに時間がかかるため、updata1関数にプログレスバーを設ける
③exshow起動時には、プログレスバーのあるrootウインドウを消したい
from PyQt5.QtWidgets import QApplication,QDialog from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout,QCheckBox,QHBoxLayout,QPushButton,QLabel,QLineEdit,QGridLayout from PyQt5.QtGui import QIcon from PyQt5 import QtGui from PyQt5.QtCore import pyqtSlot from PyQt5 import QtCore import sys from PyQt5.QtWidgets import QMessageBox from PyQt5.QtGui import QPixmap import numpy as np import os,glob,io def updata1(): global app,pro_g_bar for a in range(10):**ボールドテキスト** value = pro_g_bar.value() pro_g_bar.setValue(value + 10) QTest.qWait(1000) if value == 100: root.close() break return def main_3(): app1 = QtWidgets.QApplication(sys.argv) ex = window() ex.show() def update(): global root,app,pro_g_bar thread2=threading.Thread(target=updata1(root)) thread2.start() thread4=threading.Thread(target=updata1()) thread4.start() def reset(): global root,app,pro_g_bar value = 0 pro_g_bar.setValue(value) def main_1(): global app,pro_g_bar app = QApplication(sys.argv) root = QWidget() root.resize(300,300) root.setWindowTitle('こんにちは、世界') pro_g_bar = QtWidgets.QProgressBar(root) pro_g_bar.setGeometry(50,50,250,30) pro_g_bar.setValue(0) update_button = QtWidgets.QPushButton(root) update_button.setText("更新ボタン") update_button.clicked.connect(update) update_button.move(50,100) reset_button = QtWidgets.QPushButton(root) reset_button.setText("リセットボタン") reset_button.clicked.connect(reset) reset_button.move(50,150) root.show() sys.exit(app.exec_()) #メイン class window(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): #時間のかかる長い処理 def main_2(): global app,ex,g1,v_1,num1,num2,data,conn,ff,app1,ex #データ取得処理 thread2=threading.Thread(target=main_1()) thread2.start() return if __name__ == '__main__': main_2()
実際には、プログレスバーウインドウは消えず、メインとしたいWINDOWが落ちる。
メインwindowは起動後、ずっと継続して表示維持させたい
何卒、宜しくお願いいたします。
必要な import 文等を省略しないようにお願いします
以下です。編集いたします。
from PyQt5.QtWidgets import QApplication,QDialog
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout,QCheckBox,QHBoxLayout,QPushButton,QLabel,QLineEdit,QGridLayout
from PyQt5.QtGui import QIcon
from PyQt5 import QtGui
from PyQt5.QtCore import pyqtSlot
from PyQt5 import QtCore
import sys
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtGui import QPixmap
import numpy as np
import os,glob,io
