会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132360个问题
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 556楼
Python 全系列/第二阶段:Python 深入与提高/(旧)坦克大战 557楼

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=menuEdit)
        menubar.add_cascade(label="编辑(E)",menu=menuEdit)
        menubar.add_cascade(label="帮助(H)",menu = menuHelp)
        #添加菜单项
        menuFile.add_command(label="新建",accelerator="ctrl+n",command=self.test)
        menuFile.add_command(label="打开",accelerator = "ctrl+o", command = self.test)
        menuFile.add_command(label="保存",accelerator="ctrl+s",command=self.test)
        menuFile.add_separator()#添加分界线
        menuFile.add_command(label="退出",accelerator="ctrl+q",command=self.test)
        #将主菜单栏加到根窗口
        root["menu"] = menubar
        #文本编辑区
        self.textpad = Text(root,width=50,height=30)
        self.textpad.pack()
        def test(self):
            pass
    if __name__ == "__main__":
        root = Tk()
        root.geometry("450x300+200+300")
        root.title("百战程序员的简易记事本")
        app = Application(master=root)
        root.mainloop()  第三行不知道为什么错

image.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 558楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 559楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 560楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 561楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 562楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 564楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 565楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 566楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 567楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 568楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 570楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637