我有一个界面,提示用户输入3个输入和一个comboBox中的选择。我想要发生的是拥有用户输入的所有信息,他们按下按钮,然后这些输入用于在项目的后续过程(文件夹创建,复制等)上运行。
我的问题是我不知道如何从用户输入中获取我分配的变量。如果我在调用if___name___中的变量后放置app.exec_(),它们似乎永远不会被分配。如何调用此.py文件并将必要的输入传递给我的代码的其他部分?感谢您的帮助,我是python和qt的新手,所以如果这没有意义,请尽量澄清......
from new2 import Ui_Line
import nextProcess
from PyQt5 import QtCore, QtGui, QtWidgets
import glob, os, shutil
#GUI Called from 'new2' now apply functions to create the line based on users inputs
class window(QtWidgets.QMainWindow, Ui_Line):
def __init__(self, parent = None):
QtWidgets.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.assign)
#Function that happens when the 'click line' button is pressed
def assign(self):
num1 = str(self.num1EDIT.toPlainText())
num2 = str(self.num2EDIT.toPlainText())
num3 = str(self.num3EDIT.toPlainText())
mas = str(self.comboBox.currentText())
if mas == 'Path 1':
master = 'cbm'
elif mas == 'Path 2':
master = 'crwt'
else:
master = 'wst'
#QtCore.QCoreApplication.instance().quit()
"""Potential fix edit
proc2 = nextProcess() <---- Do I need to put nextProcess inside the assign() or in the window()?
"""
return num1, num2, num3, master
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
newWindow = window(None)
newWindow.show()
app.exec_() # <---- This is my fix, but I know this probably isn't correct
info = newWindow.assign()
num1 = info[0]
num2 = info[1]
num3 = info[2]
master = info[3]
next = nextProcess(num1, num2, num3, master)
答案 0 :(得分:0)
不要让插槽连接到按钮的clicked()
信号退出应用程序,只需让它运行您对使用适当值感兴趣的代码。
因此,assign()
方法可以更恰当地命名为callNextProcess()
,它会从小部件中检索值,并直接调用nextProcess()
。