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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
           .div1{
            background-color: blue;
            width: 500px;
            height: 500px;
        }
        .div2{
            background-color:pink;
            width: 200px;
            height: 200px;
            margin: 150px;
        }
    </style>
</head>
<body>
    <div class="div1">
        div1
        <div class="div2">div2</div>
    </div>
    <!-- 鼠标事件
    1.单击:click
    2.双击:dblclick
    3.鼠标按时:mousedown
    4.鼠标抬起:mouseup
    5.鼠标移动时:mousemove

    6鼠标移入时候/移出事:(不冒泡) mouseenter/mouseleave
     7鼠标移入时候/移出事:(不冒泡) mouseover/mouseout

    -->
    <script>
    var div1=document.getElementsByClassName('div1');
    var div2=document.getElementsByClassName('div2');
    function test1() {
        console.log('这是div1');
       
    }
    function test2() {
        console.log('这是div2');
       
    }
    var EVe={
       AA: function(ele,event,fun,bool){
         if(ele.addEventListener){
           ele.addEventListener(event,fun,bool)
         }else{
                ele.attaEvent('on'+event,fun,bool)
         }
       }
    }
      EVe.AA(div1,'click',test1,false)
    </script>
</body>
</html>

啥问题

image.png

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 20581楼
WEB前端全系列/第五阶段:前后端交互/PHP、数据库编程与设计 20582楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 20585楼
Python 全系列/第一阶段:Python入门/编程基本概念 20586楼
Python 全系列/第二十三阶段:数据分析软件/SPSS 20588楼
Python 全系列/第七阶段:网页编程基础/Ajax 20589楼

from tkinter import *
import random


class Application(Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.creatWight()

    def creatWight(self):
        self.canvas = Canvas(self, width=300, height=200, bg="green")
        self.canvas.pack()
        line = self.canvas.create_line(10, 10, 30, 20, 40, 50)
        rect = self.canvas.create_rectangle(50, 50, 100, 100)
        oval = self.canvas.create_oval(50, 50, 100, 100)

        global photo
        photo = PhotoImage(file=r"e:/pycharm_professional/imgs/logo.gif")
        self.canvas.create_image(150, 170, image=photo)

        Button(self, text="画10个矩形", command=self.draw50Recg).pack(self="left")

        def draw50Recg(self):
            for i in range(0, 10):
                x1 = random.randrange(int(self.canvas["width"])/2)
                y1 = random.randrange(int(self.canvas["height"]) / 2)
                x2 = x1 + random.randrange(int(self.canvas["width"]) / 2)
                y2 = y1 +random.randrange(int(self.canvas["width"]) / 2)
                self.canvas.create_rectangle(x1, y1, x2, y2)


if __name__ == "__main__":
    root = Tk()
    root.geometry("400x300+400+300")
    root.title("canvas组件")
    app = Application(master=root)
    root.mainloop()

请问老师为什么我这结果显示对象没有属性draw50Recg010.png

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 20590楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 20591楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 20592楼
Python 全系列/第二阶段:Python 深入与提高/坦克大战 20593楼
JAVA 全系列/(旧的隐藏)第七阶段:JAVA 高级技术/Redis 20594楼

微信图片_20220109080937.png

JAVA 全系列/第一阶段:AI驱动的JAVA编程/JAVA入门和背景知识 20595楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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