|
| 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 | +from captcha.image import ImageCaptcha |
| 13 | + |
| 14 | +image = ImageCaptcha( |
| 15 | + fonts=['C:/Users/ojasg/PycharmProjects/pythonProject/Captcha_Generator/fonts/ChelseaMarketsr.ttf', 'C:/Users/ojasg/PycharmProjects/pythonProject/Captcha_Generator/fonts/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 | + |
| 23 | +def verify(): |
| 24 | + global random |
| 25 | + x = t1.get("0.0", END) |
| 26 | + if (int(x) == int(random)): |
| 27 | + messagebox.showinfo("sucsess", "verified") |
| 28 | + else: |
| 29 | + messagebox.showinfo("Alert", "Not verified") |
| 30 | + refresh() |
| 31 | + |
| 32 | + |
| 33 | +def refresh(): |
| 34 | + random = str(randint(100000, 999999)) |
| 35 | + data = image.generate(random) |
| 36 | + assert isinstance(data, BytesIO) |
| 37 | + image.write(random, 'out.png') |
| 38 | + photo = PhotoImage(file="out.png") |
| 39 | + l1.config(image=photo, height=100, width=200) |
| 40 | + l1.update() |
| 41 | + UpdateLabel() |
| 42 | + |
| 43 | + |
| 44 | +root = Tk() |
| 45 | +photo = PhotoImage(file="out.png") |
| 46 | + |
| 47 | +l1 = Label(root, image=photo, height=100, width=200) |
| 48 | +t1 = Text(root, height=5, width=50) |
| 49 | +b1 = Button(root, text="submit", command=verify) |
| 50 | +b2 = Button(root, text="refresh", command=refresh) |
| 51 | + |
| 52 | +l1.pack() |
| 53 | +t1.pack() |
| 54 | +b1.pack() |
| 55 | +b2.pack() |
| 56 | +root.mainloop() |
0 commit comments