猫史档案馆


【Python作品分享】第34课-代码框架【作业帖】

用户:威武的阿尔法qorq威武的阿尔法qorq查看:0 回复:0 评论:0 创建时间:2021-10-17T17:28:03


【作品展示】

center_image

 

【作品介绍】

jtj

 

【作品源代码】

#你们怀念的arcade它又来啦~
#导入库中大部分功能
from arcade import *
from random import*
from arcade import color
#子类继承父类Window
class MyWindow(Window):
    #初始化方法,也叫构造函数
    def __init__(self):  # 该方法在类被实例化的时候会被自动调用一次
        self.str1="你今天真好看"
        self.str2=" "*(48-len(self.str1))
        self.str3=self.str1+self.str2
        self.lst1=list(self.str3)
        shuffle(self.lst1)
        print(self.lst1)
        super().__init__()
        self.wl=SpriteList()
        self.q=Sprite("bg.png")  # 继承父类里面原有的初始化方法
        self.q.left=0
        self.q.bottom=0
        self.num=0
        for i in range(8):
            for j in range(6):
                self.w=Sprite("b1.png")
                self.w.append_texture(load_texture("b2.png"))
                self.w.position=120+80*i,100+80*j
                self.w.new=self.lst1[self.num]
                self.num+=1
                self.w.boo = False
                self.wl.append(self.w)
    #重写鼠标按下方法,当鼠标在arcade窗口中按下的时候,会自动调用
    def on_mouse_press(self, x, y,botton,m):
        hit=get_sprites_at_point((x,y),self.wl)
        for f in hit:
            f.set_texture(1)
            f.boo=True
    #重写绘制方法,这个方法在程序run()指令后,会每秒被执行60次
    def on_draw(self):
        self.q.draw()
        self.wl.draw()
        for f in self.wl:
            if f.boo:
                draw_text(f.new,f.center_x-20,f.center_y-20,color.BLACK,30,font_name="FZY4JW.TTF")
#创建MyWindow类的实例,将会自动执行 __init__ 方法里面的代码
w = MyWindow()
#运行(调用Window类中的方法)
run()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页