我对GUI设计比较陌生,我想要的很简单:
假设我有两个窗口,当第一个窗口关闭时,它将更改第二个窗口上的标签文本。
任何帮助将不胜感激!谢谢
答案 0 :(得分:-1)
我只是让自己工作,基本的想法是将一个窗口对象传递给另一个窗口进行修改。
例如,当window2关闭时,我将更改为window1:
from PyQt5 import QtWidgets
import sys
class window_1(QtWidgets.QWidget):
#Initilization stuff
def __init__(self):
super(window_1,self).__init__()
self.setGeometry(50,50,500,500)
self.Label = QtWidgets.QLabel(self)
self.Label.setGeometry(100,100,200,10)
self.Label.setText('Second Window Not closed yet')
self.show()
class window_2(QtWidgets.QWidget):
#Pass win1 object during initialization
def __init__(self,win1_obj):
super(window_2,self).__init__()
self.setGeometry(600,50,500,500)
self.win1_obj = win1_obj
self.show()
#Define what happens when window2 closes
def closeEvent(self,event):
self.win1_obj.Label.setText('Second Window closed!')
app = QtWidgets.QApplication(sys.argv)
win1 = window_1() #window1 object
win2 = window_2(win1) #pass window1 object to window2 class
sys.exit(app.exec_())