1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| import sys
from PyQt5.QtGui import QCursor, QIcon from PyQt5.QtWidgets import QApplication, QMenu, QMainWindow, QAction
class menu(QMainWindow): def __init__(self): super(menu, self).__init__() self.title = 'notepad--' self.left = 500 self.top = 1000 self.width = 600 self.height = 600 self.initUI()
def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.top, self.left, self.width, self.height) mainMenubar = self.menuBar() menu_item_name = ['fileMenu', 'editMenu', 'formatMenu', 'searchMenu', 'helpMenu'] menu_item_bar_name = ['文件', '编辑', '格式', '查看', '帮助'] for l in range(len(menu_item_name)): menu_item_name[l] = mainMenubar.addMenu(menu_item_bar_name[l])
file_name = ['新建(N)', '打开(O)', '保存(S)', '另存为(A)', '页面设置(U)', '打印(P)', '退出(X)'] file_name_as = ['new', 'open', 'save', 'save_as', 'setup', 'print', 'exit'] file_shortcut_key = ['Ctrl+N', 'Ctrl+O', 'Ctrl+S', '', '', 'Ctrl+P', '']
edit_name = ['撤销(U)', '剪切(T)', '复制(C)', '粘贴(V)', '删除(L)', '查找(F)', '查找下一个(N)', '替换(R)', '转到(G)', '全选(A)', '时间/日期(D)'] edit_name_as = ['repeal', 'cut', 'copy', 'paste', 'dele', 'search', 'search_one', 'replace', 'goto', 'check_all', 'datetimes'] edit_shortcut_key = ['Ctrl+Z', 'Ctrl+X', 'Ctrl+C', 'Ctrl+V', 'Del', 'Ctrl+F', 'F3', 'Ctrl+H', 'Ctrl+G', 'Ctrl+A', 'F5']
format_name = ['自动换行(W)', '字体(F)'] format_name_as = ['lines', 'font'] format_shortcut_key = ['', '']
search_name = ['状态栏(S)'] search_name_as = ['statusbar'] search_shortcut_key = ['']
help_name = ['查看帮助(H)', '关于记事本(A)'] help_name_as = ['lookhelp', 'about'] help_shortcut_key = ['', '']
for i in range(len(file_name_as)): file_name_as[i] = QAction(QIcon('12.png'), file_name_as[i], self) file_name_as[i].setShortcut(file_shortcut_key[i]) file_name_as[i].setText(file_name[i]) menu_item_name[0].addAction(file_name_as[i])
for i in range(len(edit_name_as)): edit_name_as[i] = QAction(QIcon('12.png'), edit_name_as[i], self) edit_name_as[i].setShortcut(edit_shortcut_key[i]) edit_name_as[i].setText(edit_name[i]) menu_item_name[1].addAction(edit_name_as[i])
for i in range(len(format_name_as)): format_name_as[i] = QAction(QIcon('12.png'), format_name_as[i], self) format_name_as[i].setShortcut(format_shortcut_key[i]) format_name_as[i].setText(format_name[i]) menu_item_name[2].addAction(format_name_as[i])
for i in range(len(search_name_as)): search_name_as[i] = QAction(QIcon('12.png'), search_name_as[i], self) search_name_as[i].setShortcut(search_shortcut_key[i]) search_name_as[i].setText(search_name[i]) menu_item_name[3].addAction(search_name_as[i])
for i in range(len(help_name_as)): help_name_as[i] = QAction(QIcon('12.png'), help_name_as[i], self) help_name_as[i].setShortcut(help_shortcut_key[i]) help_name_as[i].setText(help_name[i]) menu_item_name[4].addAction(help_name_as[i])
self.show()
if __name__ == '__main__': app = QApplication(sys.argv) s = menu() sys.exit(app.exec_())
|