字典的格式不正确,而且类的init方法左右各有两个下划线
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