Aug-23-2022, 09:42 PM
Hello,
I'm trying to pass my userInput value
This is what I have in my BX_GUI.py:
BX_Test.py Snippet:
Thanks in advance.
Full BX_GUI.py Code:
I'm trying to pass my userInput value
userInput = self.UserInputLineEdit.text()
from my BX_GUI.py to my BX_Test.py so I can use that value to populate an appropriate response. This is what I have in my BX_GUI.py:
#Submit Function def SubmitClicked(self): #Take UserInput & append it to ConvoTextBrowser & Make User Input Text Color: Amber userInput = self.UserInputLineEdit.text() self.ConvoTextBrowser.append("\n") ConvoHistory = self.ConvoTextBrowser.append(f"<p style='color:rgb(255, 170, 0)'>{userInput}</p>") return userInputAnd I want to take the userInput and carry it over to the BX_Test.py, so I can use that value in that script.
BX_Test.py Snippet:
#------------------------------------------------------------------------------------- # User Input Function - Take Commands #------------------------------------------------------------------------------------- def UserInput(): from BX_GUI import Ui_MainDisplay command = userInput return command #-------------------------------------------------------------------------------------How do I carry the userInput value from my GUI to the other Python Script & what do I have to import in order to do so?
Thanks in advance.
Full BX_GUI.py Code:
#!/usr/bin/env python3 import sys from PyQt5 import QtCore, QtWidgets, QtGui from PyQt5.QtSql import QSqlDatabase, QSqlTableModel from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QMainWindow, QLabel, QLineEdit, QTableWidget, QTableWidgetItem, QGridLayout, QVBoxLayout, QSizePolicy, QSpacerItem, QMessageBox,QSpinBox, QComboBox, QTableView,QStyledItemDelegate) from PyQt5.QtCore import Qt, QMetaObject, QCoreApplication from PyQt5.QtGui import QFont #---------------------------------------------------------------------------------------------------- # Main Display #---------------------------------------------------------------------------------------------------- class Ui_MainDisplay(QMainWindow): def __init__(self, parent = None): super(Ui_MainDisplay, self).__init__(parent) self.setObjectName("MainDisplay") self.setFixedSize(800, 665) self.setStyleSheet("background-color: rgb(0, 0, 0);") self.centralwidget = QtWidgets.QWidget(self) self.centralwidget.setObjectName("centralwidget") self.MainFrame = QtWidgets.QFrame(self.centralwidget) self.MainFrame.setGeometry(QtCore.QRect(10, 70, 781, 521)) self.MainFrame.setStyleSheet("") self.MainFrame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.MainFrame.setFrameShadow(QtWidgets.QFrame.Raised) self.MainFrame.setObjectName("MainFrame") self.ConvoTextBrowser = QtWidgets.QTextBrowser(self.MainFrame) self.ConvoTextBrowser.setGeometry(QtCore.QRect(10, 20, 271, 481)) font = QtGui.QFont() font.setFamily("Robo Sapien") font.setPointSize(10) self.ConvoTextBrowser.setFont(font) self.ConvoTextBrowser.setStyleSheet("color: rgb(0, 255, 0);") self.ConvoTextBrowser.setObjectName("ConvoTextBrowser") self.TextBrowser = QtWidgets.QTextBrowser(self.MainFrame) self.TextBrowser.setGeometry(QtCore.QRect(0, 10, 781, 501)) self.TextBrowser.setStyleSheet("color: rgb(0, 170, 0);") self.TextBrowser.setObjectName("TextBrowser") self.calendarWidget = QtWidgets.QCalendarWidget(self.MainFrame) self.calendarWidget.setGeometry(QtCore.QRect(290, 20, 312, 183)) self.calendarWidget.setStyleSheet("color: rgb(120, 120, 120);\n" "selection-color: rgb(255, 149, 0);\n" "selection-background-color: rgb(100, 100, 100);") self.calendarWidget.setObjectName("calendarWidget") self.CalendarTextBrowser = QtWidgets.QTextBrowser(self.MainFrame) self.CalendarTextBrowser.setGeometry(QtCore.QRect(295, 211, 311, 221)) font = QtGui.QFont() font.setFamily("Runlion") font.setPointSize(10) self.CalendarTextBrowser.setFont(font) self.CalendarTextBrowser.setStyleSheet("color: rgb(255, 170, 0);") self.CalendarTextBrowser.setObjectName("CalendarTextBrowser") self.TODOTextBrowser = QtWidgets.QTextBrowser(self.MainFrame) self.TODOTextBrowser.setGeometry(QtCore.QRect(620, 210, 151, 291)) font = QtGui.QFont() font.setFamily("Runlion") font.setPointSize(10) self.TODOTextBrowser.setFont(font) self.TODOTextBrowser.setStyleSheet("color: rgb(170, 0, 0);\n" "color: rgb(0, 85, 255);") self.TODOTextBrowser.setObjectName("TODOTextBrowser") self.NewsTextBrowser = QtWidgets.QTextBrowser(self.MainFrame) self.NewsTextBrowser.setGeometry(QtCore.QRect(295, 440, 311, 61)) font = QtGui.QFont() font.setFamily("Android Insomnia") self.NewsTextBrowser.setFont(font) self.NewsTextBrowser.setStyleSheet("color: rgb(255, 170, 0);") self.NewsTextBrowser.setObjectName("NewsTextBrowser") self.DateTimeTextBrowser = QtWidgets.QTextBrowser(self.MainFrame) self.DateTimeTextBrowser.setGeometry(QtCore.QRect(630, 20, 131, 41)) font = QtGui.QFont() font.setFamily("Roblox Font") font.setPointSize(10) self.DateTimeTextBrowser.setFont(font) self.DateTimeTextBrowser.setStyleSheet("color: rgb(0, 170, 0);") self.DateTimeTextBrowser.setObjectName("DateTimeTextBrowser") self.BootStatusTextBrowser = QtWidgets.QTextBrowser(self.MainFrame) self.BootStatusTextBrowser.setGeometry(QtCore.QRect(610, 70, 171, 131)) font = QtGui.QFont() font.setFamily("Robo Sapien") font.setItalic(True) self.BootStatusTextBrowser.setFont(font) self.BootStatusTextBrowser.setStyleSheet("color: rgb(0, 170, 0);") self.BootStatusTextBrowser.setObjectName("BootStatusTextBrowser") self.TextBrowser.raise_() self.ConvoTextBrowser.raise_() self.calendarWidget.raise_() self.CalendarTextBrowser.raise_() self.TODOTextBrowser.raise_() self.NewsTextBrowser.raise_() self.DateTimeTextBrowser.raise_() self.BootStatusTextBrowser.raise_() self.InputFrame = QtWidgets.QFrame(self.centralwidget) self.InputFrame.setGeometry(QtCore.QRect(110, 590, 581, 51)) self.InputFrame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.InputFrame.setFrameShadow(QtWidgets.QFrame.Raised) self.InputFrame.setObjectName("InputFrame") self.verticalLayout = QtWidgets.QVBoxLayout(self.InputFrame) self.verticalLayout.setObjectName("verticalLayout") self.UserInputLineEdit = QtWidgets.QLineEdit(self.InputFrame) font = QtGui.QFont() font.setFamily("Android Insomnia") font.setPointSize(10) self.UserInputLineEdit.setFont(font) self.UserInputLineEdit.setStyleSheet("color: rgb(255, 170, 0);\n" "") self.UserInputLineEdit.setObjectName("UserInputLineEdit") self.verticalLayout.addWidget(self.UserInputLineEdit) self.HeaderFrame = QtWidgets.QFrame(self.centralwidget) self.HeaderFrame.setGeometry(QtCore.QRect(9, 10, 781, 61)) self.HeaderFrame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.HeaderFrame.setFrameShadow(QtWidgets.QFrame.Raised) self.HeaderFrame.setObjectName("HeaderFrame") self.TitleLabel = QtWidgets.QLabel(self.HeaderFrame) self.TitleLabel.setGeometry(QtCore.QRect(0, 0, 781, 41)) font = QtGui.QFont() font.setFamily("Android Insomnia") font.setPointSize(25) font.setBold(False) font.setWeight(50) self.TitleLabel.setFont(font) self.TitleLabel.setStyleSheet("color: rgb(0, 255, 0);") self.TitleLabel.setAlignment(QtCore.Qt.AlignCenter) self.TitleLabel.setObjectName("TitleLabel") self.SystemStatusLabel = QtWidgets.QLabel(self.HeaderFrame) self.SystemStatusLabel.setGeometry(QtCore.QRect(6, 36, 771, 20)) font = QtGui.QFont() font.setFamily("Android Insomnia") font.setPointSize(10) self.SystemStatusLabel.setFont(font) self.SystemStatusLabel.setStyleSheet("color: rgb(0, 230, 0);") self.SystemStatusLabel.setAlignment(QtCore.Qt.AlignCenter) self.SystemStatusLabel.setObjectName("SystemStatusLabel") self.WeatherTextBrowser = QtWidgets.QTextBrowser(self.HeaderFrame) self.WeatherTextBrowser.setGeometry(QtCore.QRect(620, 0, 161, 61)) font = QtGui.QFont() font.setFamily("Android Insomnia") font.setPointSize(10) self.WeatherTextBrowser.setFont(font) self.WeatherTextBrowser.setStyleSheet("color: rgb(255, 170, 0);") self.WeatherTextBrowser.setObjectName("WeatherTextBrowser") self.graphicsView = QtWidgets.QGraphicsView(self.HeaderFrame) self.graphicsView.setGeometry(QtCore.QRect(560, 0, 61, 61)) self.graphicsView.setObjectName("graphicsView") self.SubmitButton = QtWidgets.QPushButton(self.centralwidget) self.SubmitButton.setGeometry(QtCore.QRect(700, 600, 91, 41)) font = QtGui.QFont() font.setFamily("Lethal Injector") font.setPointSize(10) font.setBold(True) font.setWeight(75) self.SubmitButton.setFont(font) self.SubmitButton.setStyleSheet("background-color: rgb(170, 170, 0);\n" "background-color: rgb(200, 133, 0);") self.SubmitButton.setObjectName("SubmitButton") self.OnOffButton = QtWidgets.QPushButton(self.centralwidget) self.OnOffButton.setGeometry(QtCore.QRect(10, 600, 91, 41)) font = QtGui.QFont() font.setFamily("Lethal Injector") font.setPointSize(10) font.setBold(True) font.setWeight(75) self.OnOffButton.setFont(font) self.OnOffButton.setStyleSheet("background-color: rgb(170, 0, 0);") self.OnOffButton.setObjectName("OnOffButton") self.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(self) self.statusbar.setObjectName("statusbar") self.setStatusBar(self.statusbar) self.retranslateUi(self) QtCore.QMetaObject.connectSlotsByName(self) #---------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------- # Button Actions #---------------------------------------------------------------------------------------------------- #------------------------------------------ #Submit Button #------------------------------------------ #When the Submit button is clicked -> submitClicked Function SubmitButton = self.SubmitButton SubmitButton.clicked.connect(self.SubmitClicked) #------------------------------------------ #Submit Function def SubmitClicked(self): #Take UserInput & append it to ConvoTextBrowser & Make User Input Text Color: Amber userInput = self.UserInputLineEdit.text() self.ConvoTextBrowser.append("\n") ConvoHistory = self.ConvoTextBrowser.append(f"<p style='color:rgb(255, 170, 0)'>{userInput}</p>") return userInput #---------------------------------------------------------------------------------------------------- # Retranslate Ui #---------------------------------------------------------------------------------------------------- def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate self.setWindowTitle(_translate("MainWindow", "MainWindow")) self.ConvoTextBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Robo Sapien\'; font-size:10pt; font-weight:400; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Hello Commander. How may I be of service?</p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">What is 1 + 1?</p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">1 + 1 = 2</p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Thanks.</p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">No problem.</p></body></html>")) self.CalendarTextBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Runlion\'; font-size:10pt; font-weight:400; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">August 21 2022</p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">-Dentist appointment @ 2:00pm</p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">-Doctor\'s Appointment @ 3:00pm</p></body></html>")) self.TODOTextBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Runlion\'; font-size:10pt; font-weight:400; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600; font-style:italic;\">Todo:</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600; font-style:italic;\"><br /></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600; font-style:italic;\">-Fix Anycubic Mega X PRinter</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600; font-style:italic;\"><br /></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600; font-style:italic;\">-Work on B.A.X.T.E.R</span></p></body></html>")) self.NewsTextBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Android Insomnia\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">Todays\' News</span></p>\n" "<p align=\"center\" style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;\"><br /></p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:10pt;\">- News Headline 1</span></p></body></html>")) self.DateTimeTextBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Roblox Font\'; font-size:10pt; font-weight:400; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Date: 08/21/22</p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Time: 07:15:20pm</p></body></html>")) self.BootStatusTextBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Robo Sapien\'; font-size:8.25pt; font-weight:400; font-style:italic;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Starting Systems...</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Systems Started...</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Connecting to Databases...</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Databases - online</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Checking Connections...</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Defense Arm - Online</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">V.L.A.D 001 - Online</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">V.L.A.D 002 - Online</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Neural Network - Online</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Establishing Link...</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">Secure Link Established...</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">---</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">All Systems Running</span></p>\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:8pt;\">---</span></p></body></html>")) self.TitleLabel.setText(_translate("MainWindow", "B.A.X.T.E.R")) self.SystemStatusLabel.setText(_translate("MainWindow", "Systems Online")) self.WeatherTextBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Android Insomnia\'; font-size:10pt; font-weight:400; font-style:normal;\">\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">ThunderStorms</p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">22.9 Celcius</p>\n" "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Feels Like: 23.4</p></body></html>")) self.SubmitButton.setText(_translate("MainWindow", "Submit")) self.OnOffButton.setText(_translate("MainWindow", "Mic Offline")) #---------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------- # Run this Program #---------------------------------------------------------------------------------------------------- def main(): app = QApplication(sys.argv) win = Ui_MainDisplay() win.show() sys.exit(app.exec_()) if __name__ == "__main__": main() #----------------------------------------------------------------------------------------------------