Pyqt Lineedit Is Empty When Called From Another Script
This is my mainscript which calls some generated UI and defines a few functions: import uifile from PyQt5 import QtWidgets import sys class App(QtWidgets.QMainWindow, uifile.Ui_M
Solution 1:
EDIT:
On second thoughts, the right approach depends on how mainscript
is used. If it is used as the start-up script, it will not be initially imported, which then complicates things when it comes to accessing its globals later on.
A better approach is to have a very simple start-up script that only has this in it:
# mainscriptif __name__ == '__main__':
from mainmodule import main
main()
The mainmodule
would then look like this:
# mainmoduleimport sys
from PyQt5 import QtWidgets
import uifile
classApp(QtWidgets.QMainWindow, uifile.Ui_MyWindow):
def__init__(self):
super().__init__()
self.setupUi(self)
self.btn_clickMe.clicked.connect(self.some_function)
defsome_function(self):
import othermodule
othermodule.print_user()
definput_user(self):
user = self.lineEdit_username.text()
return user
form = Nonedefmain_window():
return form
defmain():
global form
app = QtWidgets.QApplication(sys.argv)
form = App()
form.show()
app.exec_()
And othermodule
would look like this:
# othermoduleimport mainmodule
defprint_user():
print("user input: " + mainmodule.main_window().input_user())
Post a Comment for "Pyqt Lineedit Is Empty When Called From Another Script"