如何在主窗口中显示结果?我做出了选择,通过按下按钮,我将函数的结果输出到终端,但是如何输出到这个窗口或让一个新窗口,要创建什么小部件?
import sys
from PyQt5.QtCore import *
from PyQt5 import *
from PyQt5.QtWidgets import *
class stackedExample(QWidget):
def do_leftbar(self):
self.leftlist.insertItem(0, 'Сравнение справочников') # insertItem(позиция в списке, текст)
self.leftlist.insertItem(1, 'Редактирование справочников')
# self.leftlist.insertItem(2, 'Будущий функционал')
def __init__(self):
super().__init__()
self.leftlist = QListWidget()
self.do_leftbar()
self.stack1 = QWidget()
self.stack2 = QWidget()
self.stack1UI()
self.stack2UI()
self.Stack = QStackedWidget(self)
self.Stack.addWidget(self.stack1) # возвращает индекс виджета addWidget
self.Stack.addWidget(self.stack2)
hbox = QHBoxLayout(self) # расположение макета
hbox.addWidget(self.leftlist)
hbox.addWidget(self.Stack)
self.setLayout(hbox)
self.leftlist.currentRowChanged.connect(self.display)
self.button.clicked.connect(self.gooo)
self.setGeometry(100, 100, 500, 500)
self.setWindowTitle('StackedWidget demo')
self.show()
def gooo(self):
if(self.L1.isChecked()):
print("L1 tyt my_function")
elif (self.L2.isChecked()):
print("L2")
elif (self.L3.isChecked()):
print("L3")
else:
print("select")
def stack1UI(self):
layout = QFormLayout()
face = QHBoxLayout()
self.button = QPushButton("GO")
self.L1 = QRadioButton("L1")
self.L2 = QRadioButton("L2")
self.L3 = QRadioButton("L3")
face.addWidget(self.L1)
face.addWidget(self.L2)
face.addWidget(self.L3)
layout.addRow(QLabel("select"), face)
layout.addWidget(self.button)
self.stack1.setLayout(layout)
def stack2UI(self):
layout = QFormLayout()
self.stack2.setLayout(layout)
def display(self,i):
print(i)
self.Stack.setCurrentIndex(i)
class great(QMainWindow, QWidget):
def __init__(self):
super().__init__()
a = stackedExample()
self.setGeometry(100, 100, 1000, 900)
self.setCentralWidget(a)
self.show()
def main():
app = QApplication(sys.argv)
ex = stackedExample()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我建议添加一个小部件
QTextEdit()
并在那里显示所有内容。