Python和qtDesigner中的uic弹出窗口lineEdit访问

huangapple go评论71阅读模式
英文:

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&quot;D:\UI_test\gui\main_gui_TT.ui&quot;)

appedit = QApplication([]) #Pop-up
uiedit = uic.loadUi(r&quot;D:\UI_test\gui\input_TT.ui&quot;)

def edit1():
    uiedit.show()
    appedit.exec_()
    uiedit.lineEdit_CC.setText(&#39;text&#39;) &lt;-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&quot;D:\UI_test\gui\main_gui_TT.ui&quot;)

uiedit = uic.loadUi(r&quot;D:\UI_test\gui\input_TT.ui&quot;)


def edit1():
    uiedit.show()
    uiedit.lineEdit_CC.setText(&quot;text&quot;)


ui.pushButton_1edit.pressed.connect(edit1)
ui.show()
app.exec_()

huangapple
  • 本文由 发表于 2020年1月3日 20:40:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578824.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定