|
| 1 | +""" |
| 2 | +Instructions |
| 3 | +1. Install captcha: pip install captcha |
| 4 | +2. download fonts and update the path in code |
| 5 | +3. run the code |
| 6 | +""" |
| 7 | + |
| 8 | +from io import BytesIO |
| 9 | +from tkinter import * |
| 10 | +from random import * |
| 11 | +from tkinter import messagebox |
| 12 | +import string |
| 13 | +from captcha.image import ImageCaptcha |
| 14 | + |
| 15 | +image = ImageCaptcha(fonts=['C:/Users/Administrator/Downloads/ChelseaMarketsr.ttf', 'C:/Users/Administrator/Downloads/DejaVuSanssr.ttf']) |
| 16 | + |
| 17 | +random=str(randint(100000,999999)) |
| 18 | +data = image.generate(random) |
| 19 | +assert isinstance(data, BytesIO) |
| 20 | +image.write(random,'out.png') |
| 21 | + |
| 22 | +def verify(): |
| 23 | + global random |
| 24 | + x=t1.get("0.0",END) |
| 25 | + if (int(x)==int(random)): |
| 26 | + messagebox.showinfo("sucsess", "verified") |
| 27 | + else: |
| 28 | + messagebox.showinfo("Alert", "Not verified") |
| 29 | + refresh() |
| 30 | + |
| 31 | +def refresh(): |
| 32 | + random=str(randint(100000,999999)) |
| 33 | + data = image.generate(random) |
| 34 | + assert isinstance(data, BytesIO) |
| 35 | + image.write(random,'out.png') |
| 36 | + photo = PhotoImage(file="out.png") |
| 37 | + l1.config(image=photo,height=100,width=200) |
| 38 | + l1.update() |
| 39 | + UpdateLabel() |
| 40 | + |
| 41 | +root=Tk() |
| 42 | +photo = PhotoImage(file="out.png") |
| 43 | + |
| 44 | +l1=Label(root,image=photo,height=100,width=200) |
| 45 | +t1=Text(root,height=5,width=50) |
| 46 | +b1=Button(root,text="submit",command=verify) |
| 47 | +b2=Button(root,text="refresh",command=refresh) |
| 48 | + |
| 49 | +l1.pack() |
| 50 | +t1.pack() |
| 51 | +b1.pack() |
| 52 | +b2.pack() |
| 53 | +root.mainloop() |
| 54 | + |
| 55 | + |
| 56 | + |
0 commit comments