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

#coding=utf-8
'''组件对象的绑定
1.通过command属性绑定(适合简单不需获取event对象) Button(root,text="登录",command=login)
2.通过bind()方法绑定(适合需要获取evnet对象) c1 = Canvas(); c1.bind("<Button-1>",drawLine)
   组件类的绑定
调用对象的bind_class函数,将该组件类所有的组件绑定事件:
w.bind_class("Widget","event",eventhanler) 比如:btn01.bind_class("Button","<Button-1>",func)
'''
#多种事件绑定方式汇总
from tkinter import *
root = Tk()
root.geometry("270x30")

def mouseTest1(event):
    print("bind()方式绑定,可获取event对象")
    print(event.widget)

def mouseTest2(a, b):
    print("a={0}, b={1}".format(a, b))
    print("command方式绑定,不能直接获取event对象")

def mouseTest3(event):
    print("钟呢呢右键单击事件,绑定给所有按钮啦!!")
    print(event.widget)

b1 = Button(root, text="测试bind()绑定") #第一个按钮b1
b1.pack(side="left")
b1.bind("<Button-1>", mouseTest1) #bind方式绑定事件

b2 = Button(root, text="测试command绑定", command=lambda: mouseTest2("xiannv", "zhongnene"))#第二个按钮b2 通过lambda直接传参
b2.pack(side="left")

b1.bind_class("<Button>", "<Button-2>", mouseTest3)#给所有Button按钮都绑定右键单击事件<Button-2>

root.mainloop()

<button-2>为鼠标中键,然而单击鼠标中键没反应

看视频高老师是单击的鼠标右键 我也试了但也没反应

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 26416楼
Python 全系列/第十阶段:Flask百战电商后台项目/Flask百战电商后台项目 26417楼

'''
定义一个 Employee 雇员类,要求如下:
(1) 属性有:id、name、salary
(2) 运算符重载+:实现两个对象相加时,默认返回他们的薪水和
(3) 构造方法要求:输入 name、salary,不输入 id。id 采用自增的方式,从 1000 开始自增,第一个新增对象是 1001,第二个新增对象是 1002
(4) 根据 salary 属性,使用@property 设置属性的 get 和 set 方法。set 方法要求输入:1000-50000 范围的数
'''
class Employee:
    id=1000
    def __init__(self,name,salary):
        self.__name=name
        self.__salary=salary
        Employee.id+=1
    def __add__(self, other):
        if isinstance(other,Employee):
            return self.__salary+other.__salary
    @property
    def salary(self):
        if 1000<self.__salary<50000:
            return self.__salary
        else:
            return '录入错误,薪水在1000到50000这个范围'
    @salary.setter
    def salary(self,salary):
        if 1000<salary<50000:
            self.__salary=salary
        else:
            return '薪水录入错误!只能在1000-50000之间'
emp1=Employee('高淇',30000)
print(emp1.id)
print(emp1.salary)
emp2=Employee('高希希',20000)
print(emp2.id)
print(emp2.salary)
emp2.salary=60000
print(emp1+emp2)

1.为什么emp2.salary=60000 并没有执行?

image.png

2.在运行emp2后再输出emp1.id,emp1.id就会等于emp2.id  请问老师这种情况正常吗?

image.png

image.png


Python 全系列/第一阶段:Python入门/面向对象 26421楼
JAVA 全系列/(隐藏)第二十三阶段:数字货币交易所项目/IASS基础服务的搭建和开发 26423楼
JAVA 全系列/第八阶段:Linux入门到实战/Linux(旧) 26424楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--1.描述:多了一个表单数据
2.语法:var formData=new FormData();
        formData.append("key",value);
        xhr.send(formData);


        -->
 <label for="username">
        <span>用户名:</span><input type="text" id="username" class="username">
    </label>
    <br/>
    <label for="password">
        <span>密码:</span><input type="password" id="password" class="password">
    </label>
    <br/>
    <button>点击</button>
    <script>
//      把输入的用户名和密码拿到
 var usernameInput=document.querySelector(".username");
 var passwordInput=document.querySelector(".password");
 var btn=document.querySelector("button");
//      开始构建ajax请求
 btn.onclick=function () {
            var xhr=new XMLHttpRequest();
 xhr.onreadystatechange=function () {
                if(xhr.readyState==4){
                    if(status==200){
                        console.log(JSON.parse(xhr.responseText));
 }
                }

            }
//      开始发送ajax请求
 xhr.open("post","02post请求.php",true);
//      构建post表单数据,使用 FormData()
 var datas=new FormData();
//      添加数据
 datas.append("user",usernameInput.value);
 datas.append("pass",passwordInput.value);
//      发送
 xhr.send(datas);

 }




    </script>
</body>
</html>

image.png

image.png

WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 26427楼
JAVA 全系列/第八阶段:Linux入门到实战/Linux(旧) 26428楼
微服务/第十八阶段:数字货币交易所项目(Spring Cloud Alibaba架构)/服务中台_后台管理系统的开发 26429楼
微服务/第十八阶段:数字货币交易所项目(Spring Cloud Alibaba架构)/服务中台_后台管理系统的开发 26430楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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