会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133674个问题
JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 23162楼
WEB前端全系列/第七阶段:ECMAScript6新特性模块/ES6第一部分 23163楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 23164楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/JAVA入门和背景知识 23165楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1{
            width: 100%;
            height: 50px;
            background-color: blue;
        }
        .wrap{
            width: 700px;
            height: 50px;
            margin: 0 auto;
            background-color: cadetblue;
            padding-top: 10px;
        }
        .box2{
            width: 700px;
            height: 100px;
            background-color: cadetblue;
            margin: 10px auto 0px auto;
            padding-top: 20px;
        }
        .box3{
            width: 700px;
            height: 20px;
            background-color: gray;
            margin: 0 auto;
        }
        .box4{
            width: 700px;
            height: 40px;
            background-color: green;
            margin: 0 auto;
            padding-top: 50px;

        }
        .box5{
            width: 700px;
            height: 250px;
            background-color: gray;
            margin: 0 auto;
            margin-top:40px;

        }
        .box6{
            width: 700px;
            height: 20px;
            background-color: dodgerblue;
            margin: 10px auto 0px auto;
        }
        .num1{
            padding-left: 50%;
            padding-right: 50%;
        }
        .num2{
            padding-left: 50%;
            padding-right: 50%;
        }
        .num3{
            padding-left: 50%;
            padding-right: 50%;
        }
    </style>
</head>
<body>
<div class="box1">
    <div class="wrap"><span class="num1">top1</span></div>
</div>

<div class="box2" ><span class="num2">middle1</span></div>
<div class="box3"></div>
<div class="box4" ><span class="num3">middle2</span></div>
<div class="box5"></div>
<div class="box6"></div>
</body>
</html>

blob.png我写出来效果不对哎

WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 23166楼
JAVA 全系列/第五阶段:网页编程和设计/CSS3(旧) 23167楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask之Jinja2模版 23168楼

webdemo.rar

blob.pngblob.pngblob.pngblob.pngblob.pngblob.png老师,这输入正确的用户名和密码也一直报错,老师您看是什么问题,怎么解决呢

JAVA 全系列/第六阶段:JavaWeb开发/Web实战案例 23169楼

老师你好,我按老师敲的代码后出现以下错误,是怎么回事

"""开发记事本软件的菜单
"""

from tkinter.filedialog import *
from tkinter.colorchooser import *
from tkinter.filedialog 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.newfile)
        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="crtl+q",command=self.exit)

        #将主菜单栏加到根窗口
        root["menu"]=menubar

        #增加快捷键的处理
        root.bind("<Control-n>",lambda event:self.newfile())
        root.bind("<Control-o>",lambda event:self.openfile())
        root.bind("<Control-s>",lambda event:self.savefile())
        root.bind("<Control-q",lambda event:self.exit())

        #文本剪辑区
        self.textpad=Text(root,width=50,height=30)
        self.textpad.pack()

        #创建上下菜单
        self.contextMenu=Menu(root)
        self.contextMenu.add_command(label="背景颜色",command=self.openAskColor)

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

    def newfile(self):
        self.filename=askopenfilename(title="另存为",initialfile="未命名.txt",
                                      filetypes=[("文本文档","*.txt")],
                                      defaultextension="*.txt")
        self.savefile()

    def openfile(self):
        self.textpad.delete("1.0","end")
        with askopenfile(title="打开文本文件") as d:
    # print(d.read())
             self.textpad.insert(INSERT,d.read())
             self.filename = d.name
    def savefile(self):
        with open(self.filename,"w") as d:
            c = self.textpad.get(1.0,END)
            d.write(c)

    def exit(self):
        root.quit()



    def openAskColor(self):
        s1=askcolor(color="red",title="选择背景色")
        self.textpad.config(bg=s1[1])

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

image.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 23170楼
Python 全系列/第一阶段:Python入门/编程基本概念 23171楼
JAVA 全系列/第十五阶段:Spring Session会话管理/Spring Session 23172楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用Nginx实现负载均衡及整体环境部署 23173楼

老师你好 按老师的代码敲后 新建文件的时候 选项没有保存,只有打开的选项。没有保存的选项,而且文本类型没有后缀

"""开发记事本软件的菜单
"""

from tkinter.filedialog import *
from tkinter.colorchooser import *
from tkinter.filedialog 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.newfile)
        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="crtl+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 newfile(self):
        self.filename=askopenfilename(title="另存为",initialfile="未命名.txt",
                                      filetypes=[("文本文档","*.txt")],
                                      defaultextension="*.txt")
        self.savefile()

    def openfile(self):
        self.textpad.delete("1.0","end")
        with askopenfile(title="打开文本文件") as d:
    # print(d.read())
             self.textpad.insert(INSERT,d.read())
             self.filename = d.name
    def savefile(self):
        with open(self.filename,"w") as d:
            c = self.textpad.get(1.0,END)
            d.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=Application(master=root)
    root.mainloop()

代码如上,图片如下

image.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 23174楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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