|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from tkinter import *
import random
from PIL import Image,ImageDraw,ImageTk
def right():
global strs
if strs.lower()==strs_entry.get().lower():
print('ok')
else:
print('error')
def yzm():
global strs
global img
res = ''
img1 = Image.new(mode="RGB",size=(120,30),color=(255,255,255))
draw1=ImageDraw.Draw(img1,mode="RGB")
for i in range(5):
#a-z A-Z 0-9随机生成
char1=random.choice([chr(random.randint(65,90)),
chr(random.randint(97,122)),
str(random.randint(0,9))])
#颜色随机生成
color1=(random.randint(0,255),
random.randint(0,255),
random.randint(0,255))
#书写
draw1.text([i*24,0],text=char1,fill=color1)
res+=char1
strs=res
img=img1
print(strs)
strs=''
img=None
yzm()
root = Tk()
strs_entry = Entry(root,width=6)
strs_entry.pack()
img = ImageTk.PhotoImage(img)
Label(root,image=img).pack()
Button(root,text='验证',command=right).pack()
mainloop() |
|