Python & qtDesigner uic pop-up window lineEdit access

谁说我不能喝 提交于 2020-01-22 01:16:45

问题


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:


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_()


来源:https://stackoverflow.com/questions/59578824/python-qtdesigner-uic-pop-up-window-lineedit-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!