This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
capthca.py
71 lines (57 loc) · 2.09 KB
/
capthca.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image
import math
class capthca():
datam = None
root = None
win = None
backdata = None
def __init__(self,data):
self.root = Tk()
self.win = Canvas(self.root, width=255, height=255)
self.win.grid()
self.datam = data
self.display_image()
self.display_the_query()
mainloop()
def close_window(self):
# root.destroy()
self.root.destroy()
def onclick(self):
print("You clicked the button")
def display_image(self):
img = PhotoImage(data=self.datam)
self.win.create_image(70, 200, anchor=NW, image=img)
label = Label(image=img)
label.image = img # keep a reference!
#rectangle_back = win.create_rectangle(555, 200, 300, 300, fill="gray")
def display_the_query(self):
query_label = Label(self.root,
text="Enter Captcha Code: ")
query_entry = Entry(self.root)
# to be able to track the entry text
# . notation to attach it as an attribute
query_entry.var = StringVar()
'''
Label(self.root, text="Enter your name:").pack(side=TOP)
ent = Entry(self.root)
ent.bind("<Return>", (lambda event: self.okey(ent.get())))
ent.pack(side=TOP)
btn = Button(self.root, text="Submit", command=(lambda: self.okey(ent.get())))
btn.pack(side=LEFT)
'''
# to attaching the attribute as the displayed text
query_entry['textvariable'] = query_entry.var
result_label = Label(self.root)
# to actually track the input each time there's a difference
# which essentially allows dynamically calculating the result
query_entry.bind("<Return>", (lambda event: self.okey(query_entry.var)))
query_label.grid()
query_entry.grid()
result_label.grid()
def okey(self,var):
user_input = var.get()
if user_input:
self.backdata = user_input
self.close_window()