会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132474个问题
Python 全系列/第十阶段:Flask百战电商后台项目/Flask百战电商后台项目 30556楼
Python 全系列/第十五阶段:Python 爬虫开发/爬虫反反爬- 30560楼
JAVA 全系列/预科阶段:职业规划/学习方法/程序员的基本素养和职业规划 30561楼
JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解 30566楼
WEB前端全系列/第十九阶段:Vue2知识体系(旧)/可复用性 & 组合 30568楼

代码:

tkinter *
tkinter.filedialog *  tkinter.colorchooser * tkinter.filedialog *

Application(Frame):

    (master=):
        ().(master)  .master = master
        .textpad = .pack()
        .createWidget()

    ():
        menubar = Menu(root)

        menuFile = Menu(menubar)
        menuEdit = Menu(menubar)
        menuHelp = Menu(menubar)

        menubar.add_cascade(==menuFile)
        menubar.add_cascade(==menuEdit)
        menubar.add_cascade(==menuHelp)

        menuFile.add_command(===.test)
        menuFile.add_command(===.openfile)
        menuFile.add_command(===.savefile)

        menuFile.add_separator()  menuFile.add_command(===.exit)

        root[] = menubar

        .textpad = Text(root==)
        .textpad.pack()

        .contextMenu = Menu(root)
        .contextMenu.add_command(==.openAskColor)

        root.bind(.createContextMenu)

    ():
        .textpad.delete()  (askopenfilename(=)=) f:  .textpad.insert(INSERTf.read())
            .filename = f.name

    ():
        (.filename) f:
            c = .textpad.get(END)
            f.write(c)

    ():
        root.quit()

    ():
        ():
        s1 = askcolor(==)
        root.config(=s1[])

    (event):
        .contextMenu.post(event.x_rootevent.y_root)


__name__ == :
    root = Tk()
    root.geometry()
    root.title()
    app = Application(=root)
    root.mainloop()


控制台:

C:\Users\微软\AppData\Local\Programs\Python\Python37\python.exe C:/Users/微软/pycharm_execrise/pythonProject/GUI/note.py

Exception in Tkinter callback

Traceback (most recent call last):

  File "C:\Users\微软\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__

    return self.func(*args)

  File "C:/Users/微软/pycharm_execrise/pythonProject/GUI/note.py", line 62, in openfile

    self.textpad.insert(INSERT, f.read())

  File "C:\Users\微软\AppData\Local\Programs\Python\Python37\lib\codecs.py", line 322, in decode

    (result, consumed) = self._buffer_decode(data, self.errors, final)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 0: invalid start byte


Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 30569楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 30570楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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