用pyside6写工具面板的尝试(工具v3)
This commit is contained in:
parent
b50b1e301c
commit
bfbb4213bf
|
|
@ -0,0 +1,61 @@
|
||||||
|
import sys
|
||||||
|
from PySide6.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QWidget, QLineEdit
|
||||||
|
from PySide6.QtGui import QAction
|
||||||
|
|
||||||
|
class MyWindow(QMainWindow):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.setWindowTitle("Menu Example")
|
||||||
|
self.resize(800, 600)
|
||||||
|
|
||||||
|
# Create a menu bar
|
||||||
|
menu_bar = self.menuBar()
|
||||||
|
|
||||||
|
# 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