会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132421个问题

from flask import Flask,request,render_template

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/article/<id>/')
def list(id):
    print(id)
    return 'success your id is %s'%id

@app.route('/article2/<uuid:id>/')
def list2(id):
    print(id)
    return 'success your id is %s'%id
# import uuid
# print(uuid.uuid4())
#@app.route('/list7')#这种写法方式只支持get请求方式   不支持post请求方式
@app.route('/list7',methods=['GET','POST'])#这种写法方式支持get请求方式 支持post请求方式
def list7():
    if request.method=='GET':
        pwd = request.args.get('pwd')
        uname = request.args.get('uname')
        # return 'success: %s ,%s'%(uname,pwd)
        return render_template('login.html')
    elif request.method=="POST":
        uname=request.form.get('uname')
        pwd=request.form.get('pwd')
        return 'post请求成功: %s ,%s'%(uname,pwd)
if __name__ == '__main__':
    app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h4>登陆页面</h4>
    <form action="/list7" method="post"></form>
    用户名:<input type="text" name="uname"><br>
    密&nbsp;码:<input type="password" name="pwd"><br>
    <input type="submit" value="登录">
</body>
</html>

image.png

为什么点击登录没有反应

Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图基础和URL 33227楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 33228楼
Python 全系列/第一阶段:Python入门/序列 33229楼
Python 全系列/第一阶段:Python入门/序列 33230楼

"""记事本基本编程"""

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

class Application(Frame):

    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.pack()
        self.creakWidget()

    def creakWidget(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="ctrl+q", command=self.exit)

        """增加编辑菜单项"""
        menuEdit.add_command(label="复制", command=self.copyEdit)
        menuEdit.add_command(label="粘贴", command=self.pasteEdit)

        """增加帮助菜单项"""
        menuHelp.add_command(label="查看帮助(H)", command=self.openHelp)

        """增加快捷键功能"""
        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.contextMenu = Menu(root)
        self.contextMenu.add_command(label="背景颜色", command=self.askColor)

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

        """将主菜单加入到跟窗口下"""
        root["menu"] = menubar

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

    def newFile(self):
        self.textpad.delete(1.0, END)
        self.filename = asksaveasfilename(title="另存为", initialfile="未命名.txt", filetypes=[("文本文档","*.txt")],
                                          defaultextension=".txt")
        print(self.filename)
        self.saveFile()        # 调用saveFile直接进行保存

    def openFile(self):
        self.textpad.delete(1.0, END)
        try:
            with askopenfile(title="打开文件") as f:
                self.textpad.insert(INSERT, f.read())    # 将文本内容插入到textpad中
                self.filename = f.name
                print(f.name)
        except BaseException as e:
            print(e)

    def saveFile(self):
        try:
            with open(self.filename, "w") as f:
                a = self.textpad.get(1.0, END)
                f.write(a)
        except BaseException as e:
            print(e)

    def exit(self):
        root.quit()

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

    def creakContextMenu(self,event):
        """菜单在鼠标右键点击的坐标处显示"""
        self.contextMenu.post(event.x_root, event.y_root)

    def openHelp(event):
        webbrowser.open("http://www.baidu.com")

    def copyEdit(self):
        c = self.textpad.get(1.0, END)

    def pasteEdit(self,c):
        print(c)



if __name__ == "__main__":
    root = Tk()
    root.geometry("350x400+200+300")
    app = Application(master=root)
    root.title = "百战程序员简易记事本"
    root.mainloop()

我的问题是:

    def copyEdit(self):
        c = self.textpad.get(1.0, END)

    def pasteEdit(self,c):
        print(c)

请问老师,怎么修改代码可以把copyEdit类里面的c变量复制到pasteEdit类里面去呢?

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 33231楼
WEB前端全系列/第十四阶段:微信小程序/实战_百战商城 33232楼
Python 全系列/第十五阶段:Python 爬虫开发/爬虫基础 33233楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask高级 33235楼
Python 全系列/第一阶段:Python入门/函数和内存分析 33236楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用Solr实现数据搜索 33239楼
Python 全系列/第一阶段:Python入门/编程基本概念 33240楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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