会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132450个问题
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 6347楼

"""菜单栏软件的开发"""

from tkinter import *
from tkinter.colorchooser import *
from tkinter.filedialog import *

class Apllication(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.test)
        menuFile.add_command(label="打开", accelerator="ctrl+o", command=self.openfile)
        menuFile.add_command(label="保存", accelerator="ctrl+s", command=self.savefile)
        menuFile.add_separator()    #增加分界线
        menuFile.add_command(label="退出", accelerator="ctrl+q", command=self.exit)

        #将主菜单添加到根窗口
        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.test)

        #为右键绑定事件
        root.bind("<Button-3>",self.createContextMenu)


    def openfile(self):
        self.textpad.delete(1.0,END)
        with askopenfile(title="打开文本文件") as f:
            self.textpad.insert(INSERT,f.read())
            self.filename = f.name


    def savefile(self):
        with open(self.filename,"w") as f :
            c = self.textpad.get(1.0,END)
            f.write(c)


    def exit(self):
        root.quit()

    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 = Apllication(master=root)
    root.mainloop()

文件和软件解码都是utf-8

为什么会出现这种情况呢

image.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 6349楼
JAVA 全系列/第十八阶段:亿级高并发电商项目/亿级高并发电商项目(旧) 6351楼
WEB前端全系列/预科阶段:职业规划/学习方法/前端技术体系 6352楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库的使用 6354楼

package com.itbaizhan;
import java.util.Arrays;//自定义一个简单的包装类,仅限于练习
public class MyInteger {
    private final int value;
    private static MyInteger[]cache;//缓存【-128,127】之间的数字
    private static  final int LOW=-128;
    private static  final  int HIGH=127;
    static {
        cache=new MyInteger[HIGH-LOW+1];
        for(int i=LOW;i<HIGH;i++){
            cache[i-LOW]=new MyInteger(i);
        }
        System.out.println(Arrays.toString(cache));
    }
    public MyInteger(int value){
        this.value=value;
    }
    @Override
    public String toString() {
        return value+"";
    }
    public static MyInteger valueof(int value){
        if(value>=LOW&&value<=HIGH){
            return  cache[value-LOW];
        }
        return  new MyInteger(value);}
    public static void main(String[] args) {
        MyInteger a=new MyInteger(10);
        MyInteger b= new MyInteger(100);
        MyInteger b2= new MyInteger(100);
        MyInteger b3 = new MyInteger(1000);
        MyInteger b4 = new MyInteger(1000);
        System.out.println(b==b2);
        System.out.println(b3==b4);
        int c=b.intvalue();  }
    public int intvalue(){
        return  value;
    }
}

不清楚为什么会输出两个false

JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 6356楼
JAVA 全系列/第九阶段:权限控制与安全认证/Spring Security(旧) 6357楼
WEB前端全系列/第十一阶段:前端工程化/Webpack 6358楼
JAVA 全系列/第九阶段:权限控制与安全认证/Spring Security(旧) 6359楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 6360楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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