鱼C论坛

 找回密码
 立即注册
查看: 792|回复: 0

[作品展示] 简单的验证码

[复制链接]
发表于 2018-8-17 13:19:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 13:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表