Python,类的用法,请看看

img

img


请问这种题应该如何做,我自己编了一点但是我觉得是错的,主要是成绩那个字典我不会做

字典的格式不正确,而且类的init方法左右各有两个下划线

  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7741877
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:python 熔断器,限流器,实现服务的熔断和限流,也可以应用与其他场景的函数超时处理和异常错误处理。
  • 你还可以看下python参考手册中的 python-函数式编程模块
  • 除此之外, 这篇博客: python,一个入门级极简单的图像处理工具(二)中的 文字添加也是如此,无法绑定鼠标,功能鸡肋,,,,镜像很简单: 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • Win类;

    # 文字添加功能窗口
        def window_word(self):
            Word_win = tk.Toplevel()
            Word_win.title('镜像操作')
            Word_win.geometry('200x250')
            l1 = tk.Label(Word_win, text='请输入文字:')
            l1.place(y=20, x=25, width=80)
            self.textWord = tk.Entry(Word_win, width=17)
            self.textWord.place(y=45, x=15)
            l2 = tk.Label(Word_win, text='请选择文字颜色:')
            l2.place(y=85, x=25, width=105)
            b1 = tk.Button(Word_win, text='红色', width=8, command=lambda: self.getWord_input('red'))
            b1.place(y=120, x=20)
            b2 = tk.Button(Word_win, text='黑色', width=8, command=lambda: self.getWord_input('black'))
            b2.place(y=120, x=100)
            b3 = tk.Button(Word_win, text='蓝色', width=8, command=lambda: self.getWord_input('blue'))
            b3.place(y=150, x=20)
            b4 = tk.Button(Word_win, text='绿色', width=8, command=lambda: self.getWord_input('green'))
            b4.place(y=150, x=100)
            b5 = tk.Button(Word_win, text='黄色', width=8, command=lambda: self.getWord_input('yellow'))
            b5.place(y=180, x=20)
            b6 = tk.Button(Word_win, text='白色', width=8, command=lambda: self.getWord_input('white'))
            b6.place(y=180, x=100)
            b7 = tk.Button(Word_win, text='完成', command=Word_win.destroy)
            b7.place(y=220, x=150)
    
    # 获得文字添加的相关对象
        def getWord_input(self, color):
            self.picture = picture()
            needWord_pic = self.img
            showWord = self.textWord.get()
            # print(showWord)
            # print(color)
            showInword_pic = self.picture.wordInput(needWord_pic, showWord, color)
            self.show_img(showInword_pic)
    
    # 镜像操作窗口
        def window_mirror(self):
            Mir_win = tk.Toplevel()
            Mir_win.title('镜像操作')
            Mir_win.geometry('150x150')
            b1 = tk.Button(Mir_win, text='左右', command=self.MirrorImg_lr)
            b1.place(y=30, x=35, width=75)
            b2 = tk.Button(Mir_win, text='上下', command=self.MirrorImg_tb)
            b2.place(y=60, x=35, width=75)
            b3 = tk.Button(Mir_win, text='完成', command=Mir_win.destroy)
            b3.place(y=110, x=80, width=40)
    
    # 镜像左右调用展示
        def MirrorImg_lr(self):
            self.picture = picture()
            Mirror_img_lr = self.img
            MittotImg_lrFinish = self.picture.MirrorPic_leftOrright(Mirror_img_lr)
            self.show_img(MittotImg_lrFinish)
    
    # 镜像上下调用展示
        def MirrorImg_tb(self):
            self.picture = picture()
            Mirror_img_tb = self.img
            MittotImg_tbFinish = self.picture.MirrorPic_topOrbuttom(Mirror_img_tb)
            self.show_img(MittotImg_tbFinish)
    

    picture类:

    # 文字添加
        def wordInput(self, pic_preWord, textEn, fillColor):
            Wordpic_width, Wordpic_height = pic_preWord.size
            wordFont = ImageFont.truetype('./use.TTF', 30)
            draw = ImageDraw.Draw(pic_preWord)
            draw.text((20, Wordpic_height - 35), text=textEn, font=wordFont, fill=fillColor)
            return pic_preWord
    
    # 镜像左右
        def MirrorPic_leftOrright(self, pic_mir_lr):
            Mirror_lrFinish = pic_mir_lr.transpose(Im.FLIP_LEFT_RIGHT)
            return Mirror_lrFinish
    
    # 镜像上下
        def MirrorPic_topOrbuttom(self, pic_mir_tp):
            Mirror_tbFinish = pic_mir_tp.transpose(Im.FLIP_TOP_BOTTOM)
            return Mirror_tbFinish
    
  • 您还可以看一下 CSDN就业班老师的Python爬虫技术和浏览器模拟,验证码识别视频教程课程中的 网络爬虫概述小节, 巩固相关知识点