首页 > 电脑

Python的简易记事本的编程,没有菜单栏,哪位大神看看啊!!!

更新时间2021-02-09 15:48:19

from tkinter.filedialog import *
from tkinter.colorchooser import *
class Application(Frame):
    def __init(self,master=None):
        super().__init__(master)
        self.master=master
        self.textpad=None
        self.pack()
        self.createWidget()
    def createWidget(self):
        menubar=Menu(root)
        menuFile=Menu(menubar)
        menuEdit=Menu(menubar)
        menuHelp=Menu(menubar)
        menubar.add_cascade(label="文件(F)",menu=menuFile)
        menubar.add_cascade(label="编辑(E)",menu=menuEdit)
        menubar.add_cascade(label="帮助(H)",menu=menuHelp
        menuFile.add_command(label="新建",accelerator="ctrl+n",command=self.aaa)
        menuFile.add_command(label="打开",accelerator="ctrl+o",command=self.aaa)
        menuFile.add_command(label="保存",accelerator="ctrl+s",command=self.aaa)
        menuFile.add_separator()
        menuFile.add_command(label="退出",accelerator="ctrl+q",command=self.aaa)
        root["menu"]=menubar
        self.textpad=Text(root,width=50,height=30)
        self.textpad.pack()
        self.contextMenu=Menu(root)
        self.contextMenu.add_command(label="背景颜色",command=self.aaa)
        root.bind("<Button-3>",self.createContextMenu)
    def test(self):
        pass
    def createContextMenu(self,event):
        self.contextMenu.post(event.x_root,event.y_root)
if __name__=='__main__':
    root=Tk()
    root.geometry("450x300+200+300")
    root.title("简易记事本")
    app=Application(master=root)
    root.mainloop()

相关标签:大神

上一篇:各位大神,帮帮我

下一篇:宏碁2012年471保款笔记本适合出差吗