英文:
Python & qtDesigner uic pop-up window lineEdit access
问题
I'm newbie.
I want to click a pushButton to open a new window and take text from main window lineEdit and copy to new pop-up window lineEdit.
So far I can create a new window but can't access lineEdit. No errors, the app is not responding.
This is what I have:
from PyQt5.QtWidgets import QApplication
from PyQt5 import uic
app = QApplication([]) # 主窗口
ui = uic.loadUi(r"D:\UI_test\gui\main_gui_TT.ui")
appedit = QApplication([]) # 弹出窗口
uiedit = uic.loadUi(r"D:\UI_test\gui\input_TT.ui")
def edit1():
uiedit.show()
appedit.exec_()
uiedit.lineEdit_CC.setText('text') # <- 这一行有问题
ui.pushButton_1edit.pressed.connect(edit1)
ui.show()
app.exec_()
Please help what is wrong here?
英文:
I'm newbie.
I want to click a pushButton to open a new window and take text from main window lineEdit and copy to new pop-up window lineEdit.
So far I an create new window but can't access lineEdit. No errors, app is not responding.
This is what I have:
from PyQt5.QtWidgets import QApplication
from PyQt5 import uic
app = QApplication([]) #Main Window
ui = uic.loadUi(r"D:\UI_test\gui\main_gui_TT.ui")
appedit = QApplication([]) #Pop-up
uiedit = uic.loadUi(r"D:\UI_test\gui\input_TT.ui")
def edit1():
uiedit.show()
appedit.exec_()
uiedit.lineEdit_CC.setText('text') <-this line is a problem
ui.pushButton_1edit.pressed.connect(edit1)
ui.show()
app.exec_()
Please help what is wrong here?
答案1
得分: 1
你应该只有一个 QApplication,即使有多个窗口,考虑到上述问题,解决方案如下:
from PyQt5.QtWidgets import QApplication
from PyQt5 import uic
app = QApplication([]) # 主窗口
ui = uic.loadUi(r"D:\UI_test\gui\main_gui_TT.ui")
uiedit = uic.loadUi(r"D:\UI_test\gui\input_TT.ui")
def edit1():
uiedit.show()
uiedit.lineEdit_CC.setText("文本")
ui.pushButton_1edit.pressed.connect(edit1)
ui.show()
app.exec_()
英文:
You should only have a single QApplication even if you have many windows, considering the above the solution is:
from PyQt5.QtWidgets import QApplication
from PyQt5 import uic
app = QApplication([]) # Main Window
ui = uic.loadUi(r"D:\UI_test\gui\main_gui_TT.ui")
uiedit = uic.loadUi(r"D:\UI_test\gui\input_TT.ui")
def edit1():
uiedit.show()
uiedit.lineEdit_CC.setText("text")
ui.pushButton_1edit.pressed.connect(edit1)
ui.show()
app.exec_()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论