I have an interface that prompts users for 3 inputs and a selection from a comboBox. What I want to happen is have all of the information entered by the user, they press the button and then those inputs are used to run on the subsequent processes for the project (folder creation, copying, ect).
My problem is that I do not know how to grab the variable I am assigning from the user inputs. If I place the app.exec_() after I am calling the variables in if___name___ they appear to never be assigned. How can call this .py file and pass the necessary inputs to the other parts of my code? Thanks for any help, I am brand new to python and qt so if this is making no sense ill try my best to clarify...
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)
Instead of having the slot connected to the push button's clicked()
signal quit the application, just have it run the code you're interested in using the appropriate values.
So the assign()
method could more aptly be named callNextProcess()
, which retrieves the values from the widgets and just calls nextProcess()
directly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.