feat(projects): 新增PySide综合案例示例代码

This commit is contained in:
100gle
2022-09-16 21:50:35 +08:00
parent c3a251aca5
commit 49e639445b
6 changed files with 484 additions and 0 deletions

53
projects/gui/widget.py Normal file
View File

@@ -0,0 +1,53 @@
import sys
from PySide6.QtWidgets import QApplication, QLabel, QLineEdit, QVBoxLayout, QWidget
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.resize(200, 200)
label = QLabel()
label.setText("Hello, World!")
label.setStyleSheet(
"""
QLabel {
font-size: 20px;
text-align: center;
margin: auto 50%;
padding-bottom: 5px;
}
"""
)
self.label = label
editor = QLineEdit()
editor.setPlaceholderText("input your name here.")
editor.textChanged.connect(self.echo)
self.editor = editor
layout = QVBoxLayout()
layout.addWidget(self.label)
layout.addWidget(self.editor)
self.setLayout(layout)
def echo(self, name: str = ""):
if name:
msg = f"Hello, {name}!"
else:
msg = f"Hello, world!"
self.label.setText(msg)
def main():
app = QApplication()
widget = MyWidget()
widget.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()