Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在pyQt5应用程序中应用多线程_Python 3.x_Multithreading_Pyqt5 - Fatal编程技术网

Python 3.x 如何在pyQt5应用程序中应用多线程

Python 3.x 如何在pyQt5应用程序中应用多线程,python-3.x,multithreading,pyqt5,Python 3.x,Multithreading,Pyqt5,我的问题是,如果用户只过滤日期,并且希望继续并将当前数据帧导出到csv,我怎么做?我很困惑。我试过开关箱,但严重失败。我认为多线程可以解决这个问题…如果你想用一个线程运行应用程序,用另一个线程运行应用程序,你可以创建一个函数来运行应用程序 代码 我的问题通过向代码的主线程添加信号得到了解决,即在其中声明UI小部件,然后在相应的函数中过滤数据帧。这让我忘记了激活过滤器,我只传递了过滤器中所需的数据帧。虽然理论上您的解决方案适用于正常情况,但GUI工具包通常需要在主线程中执行,而外部线程无法(直接)

我的问题是,如果用户只过滤日期,并且希望继续并将当前数据帧导出到csv,我怎么做?我很困惑。我试过开关箱,但严重失败。我认为多线程可以解决这个问题…

如果你想用一个线程运行应用程序,用另一个线程运行应用程序,你可以创建一个函数来运行应用程序

代码


我的问题通过向代码的主线程添加信号得到了解决,即在其中声明UI小部件,然后在相应的函数中过滤数据帧。这让我忘记了激活过滤器,我只传递了过滤器中所需的数据帧。

虽然理论上您的解决方案适用于正常情况,但GUI工具包通常需要在主线程中执行,而外部线程无法(直接)与其交互,因此,在这种情况下,QThread是必需的。此外,您的Ui_主窗口不完整,因为中心小部件从未实际设置为这样。请尝试一下@Iron Man,但这有点无关。您能否澄清您当前正在做什么以及您想要实现什么?从你的问题来看,这还不是很清楚,你提供的代码几乎是无用的,因为它是附加的图像。我没有看到任何问题描述(你只是描述了一项任务),我建议你从这个开始着手。当你遇到实际问题时,请回来。此外,这听起来可能很苛刻,但您选择了一种技术(多线程),但不知道或几乎不知道它的作用,但不知何故,您认为它与您的任务有关。这不是一个明智的决定。@Ulrich Eckhardt我知道你没有太多时间深入研究我的问题,但如果你愿意,我可以详细说明,否则有足够的小伪代码形式的信息,如果我将编写所有代码,人们会开始告诉我,这是大量需要伪代码的代码。@musicmante我使用了函数名,以便人们容易理解代码,图像也与代码相关。
def upload(self):
    # Upload File and convert it to dataframe and fill a column data to a dropdown
    # Return this dataframe 'df'

# User will select a FType from Dropdown and then below verifyFType function will be activated

def verifyFType(self):
    try:
        if(FType == "DH"):
            # Activate DH_ValidateFunction()
            # Activate Filter Function to filter data from dataframe
        elif(FType == "HSC"):
            # Activate HSC_ValidateFunction()
            # Activate Filter Function to filter data from dataframe
    except:
        pass

# One of the functions will be activated at a time 

def DH_ValidateFunction(self):
    # Calculations on some columns of pandas dataframe and return that modified dataframe
    # return final calculated dataframe 'df'

def HSC_ValidateFunction(self):
    # Calculations on some columns of pandas dataframe and return that modified dataframe
    # return final calculated dataframe 'df'

# On the basis of validation Function and final dataframe returned there will be dropdowns to filter
# data from dataframe "df"

def filterDate(self):
    # This will filter date from the dataframe "df"
    # Return filtered date dataframe "df_DATE"

def filterName(self):
    # This will filter Name from the dataframe "df"
    # Return filtered Name dataframe "df_NAME"

def EXPORT_CSV(self):
    # Export either df , df_DATE or df_NAME whatever user want at the time 
    # df.to_csv('table.csv) or df_DATE.to_csv('table.csv) or df_NAME.to_csv('table.csv)
import threading
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):

    def setupUi(self,MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        
def Run_Loop():# This function will run a while loop 
    while True:
        text =  input('Type Here: ')
        if 'break' in text:
            break
        else:
            print(text)


def Run_App():# This function runs the ui
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow) 
    MainWindow.show()
    sys.exit(app.exec_())

t1 = threading.Thread(target=Run_App)
t2 = threading.Thread(target=Run_Loop)
t1.start()
t2.start()