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

老師我已經解決了,原來在mac上menubar都會在屏幕的最頂部我沒看到以為有問題 而且選項單中為什麼ctr+n會顯示不出來我給你原代碼你試試看


"""開發記事本軟件菜單"""

from tkinter import *

class Application(Frame):

    def __init__(self, master=None):

        super().__init__(master)

        self.master = master

        self.textpad = None

        self.pack()

        self.creatWidget()

    def creatWidget(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)

        #添加菜單選項label

        menuFile.add_command(label="新建", accelerator="ctr+n", command=self.text)

        menuFile.add_command(label="打開", accelerator="ctr+o", command=self.text)

        menuFile.add_command(label="保存", accelerator="ctr+s", command=self.text)

        menuFile.add_separator() # 添加分割線

        menuFile.add_command(label="退出", accelerator="ctr+q", command=self.text)

        #將主菜單欄添加到根窗口

        root["menu"] = menubar

        #文本編輯區

        self.textpad = Text(root, width=50, height=30)

        self.textpad.pack()

    def text(self):

        pass

if __name__ == '__main__':

    root = Tk()

    root.geometry("400x300+200+300")

    root.title("記事本")

    app = Application(master=root)

    root.mainloop()

螢幕截圖 2021-03-27 上午4.38.14.png

Python全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 782楼
Python全系列/第二阶段:Python 深入与提高/模块 784楼
Python全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 785楼


微信图片_20211004105221.png

老师,画笔这里这两句是什么意思呀,一直搞不明白


Python全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 786楼
Python全系列/第二阶段:Python 深入与提高/坦克大战 787楼
Python全系列/第二阶段:Python 深入与提高/文件处理 788楼
Python全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 789楼
Python全系列/第二阶段:Python 深入与提高/异常机制 790楼
Python全系列/第二阶段:Python 深入与提高/文件处理 792楼
Python全系列/第二阶段:Python 深入与提高/异常机制 794楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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