Skip to content

Commit 4ec192b

Browse files
Merge pull request #315 from ojasggg/featCaptcha_Generator_py
feat: Captcha Generator in Python.
2 parents bfaa972 + 2306f83 commit 4ec192b

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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()

Captcha_Generator/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Captcha Genrator
2+
A simple image captcha generator
3+
4+
### Prerequisites
5+
1. Install the dependencies by executing the following command
6+
```pip install -r requirements.txt```
7+
8+
2. Update the path of font in code (if required)
9+
```image = ImageCaptcha(fonts=['<path>/ChelseaMarketsr.ttf', '<path>/DejaVuSanssr.ttf'])```
10+
11+
### Screenshot
12+
![image](https://user-images.githubusercontent.com/39544459/137623915-1e837ada-f199-4513-a15d-ecbb969fd53e.png)
13+
14+
## *Ojash Gurung*
169 KB
Binary file not shown.
724 KB
Binary file not shown.

Captcha_Generator/out.png

9.09 KB
Loading

Captcha_Generator/requirements

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
captcha

0 commit comments

Comments
 (0)