def createWidgets(self): # 创建一个Text self.text = tkinter.Text(self,width=550, height=650) self.text.pack() # 将主菜单栏加到根窗口 menu = MainMenu(root) menu.createWidget() self.mainMenu = menu.getMenu() #添加快捷键事件处理 self.root.bind("<Control-n>",lambda event:self.newfile()) self.root.bind("<Control-o>",lambda event:self.openfile()) self.root.bind("<Control-s>",lambda event:self.savefile()) self.root.bind("<Control-q>",lambda event:self.exit()) menu.bindMenuFile(newfile=self.newfile, openfile=self.openfile, savefile=self.savefile, exit=self.exit) quickMenu = QuickMenu(self.root) quickMenu.createWidget() quickMenu.bindMenu(changeBG=self.changBG) self.quickMenu = quickMenu.menu self.root["menu"] = self.mainMenu #为右键绑定事件 self.root.bind("<Button-2>",self.showQuickMenu)