氣輕PyQt6 33 多行文本框(QTextEdit)
?
from PyQt6.QtWidgets import *
from PyQt6.QtGui import QFont
import sys
?
class PyQt633(QWidget):
??? def __init__(self):
??????? super().__init__()
??????? self.initUI()
??? def initUI(self):
??????? self.setWindowTitle('氣輕PyQt6')??????????????? # 設(shè)置窗口標(biāo)題
??????? self.resize(520, 300)?????????????????????????? # 設(shè)置窗口大小
?
??????? self.edit1 = QTextEdit(self)??????????????????? # 輸入框
??????? self.edit1.setGeometry(10, 0,500, 120)????????? # 設(shè)置位置和大小
??????? self.edit1.setText('QTextEdit是多行文本框,\nQLineEdit是單行文本框。')
??????? self.edit1.setFont(QFont('Arial',20))
??????? self.edit1.setStyleSheet('background-color:#F5DEB3;color : #8B8682; \
??????????????????? font: bold large /"SimSun/";font-size:26px')
?
??????? self.edit2 = QTextEdit(self)??????????????????? # 輸入框
??????? self.edit2.setGeometry(10, 130,500, 120)??????? # 設(shè)置位置和大小
??????? self.edit2.setFont(QFont('Arial',20))
??????? self.edit2.setStyleSheet('background-color:#00E5EE;color : #1E90FF; \
??????????????????? font: bold large /"SimSun/";font-size:26px')
?
??????? self.btn = QPushButton('移動(dòng)', self)
??????? self.btn.setGeometry(230, 260, 60, 40)
??????? self.btn.setStyleSheet('background-color:#96CDCD;color : #FFE4C4; \
??????????????????? font: bold large /"SimSun/";font-size:16px')
??????? self.btn.clicked.connect(self.updateEdit)
?
??????? self.show()
?
??? def updateEdit(self):
??????? edittext = self.edit1.toPlainText()
??????? self.edit1.clear()
??????? self.edit2.setText(edittext)
?
if __name__ == '__main__':
??? app = QApplication(sys.argv)
??? window = PyQt633()
??? sys.exit(app.exec())
?
執(zhí)行結(jié)果
