# -*- coding: utf-8 -*-
from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton, QTextEdit
def sayHello():
textEdit.setText("hello")
app = QApplication([])
window = QMainWindow()
window.resize(800, 600)
window.move(300, 310)
window.setWindowTitle('MainWindow')
textEdit = QTextEdit("init-information", window)
textEdit.resize(500, 400)
textEdit.move(40, 50)
button = QPushButton('pushButton', window)
button.move(600, 300)
button.resize(130, 50)
button.clicked.connect(sayHello)
window.show()
app.exec_()
# -*- coding: utf-8 -*-
import sys
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QFile
def sayHello():
window.textEdit.setText("hello world!")
print("Button click!")
if __name__ == "__main__":
app = QApplication(sys.argv)
ui_file = QFile("UI/mainWindow.ui")
ui_file.open(QFile.ReadOnly)
loader = QUiLoader()
window = loader.load(ui_file)
ui_file.close()
# 在这里加入信号触发、空间位置控制等代码
window.pushButton.clicked.connect(sayHello)
# 添加结束
window.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
import sys
from mainWindow import Ui_MainWindow
from PySide2.QtWidgets import QMainWindow, QApplication
def signleAndSlot():
UI.pushButton.clicked.connect(sayHello)
def sayHello():
UI.textEdit.setText("Hello World!")
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = MainWindow()
UI = main.ui
# 调用信号和槽的函数以及空间管理等函数
signleAndSlot()
main.show()
sys.exit(app.exec_())
手机扫一扫
移动阅读更方便
你可能感兴趣的文章