pyside6学习中
This commit is contained in:
parent
3aa83d14cd
commit
c2333af67c
|
|
@ -1,61 +1,14 @@
|
||||||
import sys
|
from PySide6.QtWidgets import QMainWindow, QApplication, QLabel
|
||||||
from PySide6.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QWidget, QLineEdit
|
|
||||||
from PySide6.QtGui import QAction
|
|
||||||
|
|
||||||
class MyWindow(QMainWindow):
|
class MyWindow(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
lbl = QLabel("按钮", self)
|
||||||
|
lbl.setGeometry(100,100,200,100)
|
||||||
|
lbl.setText("重新设置按钮文字")
|
||||||
|
|
||||||
self.setWindowTitle("Menu Example")
|
if __name__ == '__main__':
|
||||||
self.resize(800, 600)
|
app = QApplication([])
|
||||||
|
windows = MyWindow()
|
||||||
# Create a menu bar
|
windows.show()
|
||||||
menu_bar = self.menuBar()
|
app.exec()
|
||||||
|
|
||||||
# Create "File" menu
|
|
||||||
file_menu = menu_bar.addMenu("File")
|
|
||||||
|
|
||||||
# Create "Filter" action
|
|
||||||
filter_action = QAction("Filter", self)
|
|
||||||
filter_action.triggered.connect(self.show_text_boxes)
|
|
||||||
file_menu.addAction(filter_action)
|
|
||||||
|
|
||||||
# Create "Generate" action
|
|
||||||
generate_action = QAction("Generate", self)
|
|
||||||
file_menu.addAction(generate_action)
|
|
||||||
|
|
||||||
# Create "Exit" action
|
|
||||||
exit_action = QAction("Exit", self)
|
|
||||||
exit_action.triggered.connect(self.close)
|
|
||||||
menu_bar.addAction(exit_action)
|
|
||||||
|
|
||||||
self.central_widget = QWidget()
|
|
||||||
self.setCentralWidget(self.central_widget)
|
|
||||||
self.layout = QVBoxLayout(self.central_widget)
|
|
||||||
|
|
||||||
def show_text_boxes(self):
|
|
||||||
self.clear_layout()
|
|
||||||
|
|
||||||
content_textbox = QLineEdit(self)
|
|
||||||
content_textbox.setPlaceholderText("Content")
|
|
||||||
self.layout.addWidget(content_textbox)
|
|
||||||
|
|
||||||
obj_textbox = QLineEdit(self)
|
|
||||||
obj_textbox.setPlaceholderText("Obj")
|
|
||||||
self.layout.addWidget(obj_textbox)
|
|
||||||
|
|
||||||
tag_textbox = QLineEdit(self)
|
|
||||||
tag_textbox.setPlaceholderText("Tag")
|
|
||||||
self.layout.addWidget(tag_textbox)
|
|
||||||
|
|
||||||
def clear_layout(self):
|
|
||||||
for i in reversed(range(self.layout.count())):
|
|
||||||
widget = self.layout.itemAt(i).widget()
|
|
||||||
if widget is not None:
|
|
||||||
widget.deleteLater()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
window = MyWindow()
|
|
||||||
window.show()
|
|
||||||
sys.exit(app.exec())
|
|
||||||
Reference in New Issue