feat(projects): 新增PySide综合案例示例代码
This commit is contained in:
53
projects/gui/widget.py
Normal file
53
projects/gui/widget.py
Normal 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()
|
||||
Reference in New Issue
Block a user