import sys
from PySide6 import QtCore,QtWidgets
from PySide6.QtWidgets import *
from menu_ui import Ui_MainWindow //导入ui
class menu(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.__create_connections()
self.ui.actionOpen.setShortcut('alt+o') //设置快捷方式
def __create_connections(self):
self.ui.actionOpen.triggered.connect(self.open_file) //信号
def open_file(self):
fname,_ = QFileDialog.getOpenFileName(self,"打开文件", '.')
if fname:
self.ui.lineEdit.setText(fname)
with open(fname,'r') as f:
content = f.read()
self.ui.plainTextEdit.setPlainText(str(content))
if __name__ == '__main__':
app = QApplication(sys.argv)
w = menu()
w.show()
sys.exit(app.exec())
标签:__,self,PyQt,菜单栏,ui,fname,使用,import,open
From: https://www.cnblogs.com/conpi/p/17097555.html