Skip to content

Commit 55a4cd5

Browse files
authored
Merge pull request #684 from RaveenaBhasin/virtual
Virtual Keyboard
2 parents ff8d8e5 + d092536 commit 55a4cd5

File tree

4 files changed

+290
-0
lines changed

4 files changed

+290
-0
lines changed

virtual_keyboard/Images/keyboard.png

7.14 KB
Loading

virtual_keyboard/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ✔ VIRTUAL KEYBOARD
2+
- ### A Virtual Keyboard is an application created in python with tkinter gui.
3+
- ### In this application user can enter any text or sentence or paragraph using the virtual keyboard that is embedded under keyboard button.
4+
- ### This virtual keyboard can print any character (lower or uppercase), any special characters, digits.
5+
- ### It also supports typing emoji's also.
6+
- ### Also there are clear, backspace, space, tab keys also in this virtual keyboard.
7+
8+
9+
****
10+
11+
# REQUIREMENTS :
12+
- ### python 3
13+
- ### tkinter module
14+
- ### from tkinter messagebox module
15+
16+
****
17+
18+
# How this Script works :
19+
- ### User just need to download the file and run the virtual_keyboard.py on their local system.
20+
- ### Now on the main window of the application, one START button will be there clicking on which the main window of virtual keyboard opens.
21+
- ### In this window there is a text area given, and a button KEYBOARD, clicking on which a virtual keyboard will pop up in the same frame.
22+
- ### using this virtual keyboard user can enter any text, character, any special charater, digits, and some emoji's also.
23+
- ### Inside Keyboard also there is a clear, backspace, sace, tab button also.
24+
- ### Also there is one hide button, clicking on which the virtual keyboard disappears.
25+
- ### After user has entered some text in textarea using virtual keyboard, then clicking on the PRINT button, shows messagebox, showing what is printed.
26+
- ### Also there is an exit button, clicking on which exit dialog box appears asking for the permission of the user for closing the window.
27+
28+
****
29+

virtual_keyboard/main.py

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
from tkinter import Tk, Button, END, Label, Canvas, Frame, PhotoImage, NW
2+
from tkinter import messagebox
3+
import tkinter.messagebox as mbox
4+
import tkinter as tk
5+
6+
root = Tk()
7+
root.title("Virtual Keyboard")
8+
root.geometry('1000x700')
9+
10+
11+
class Keypad(tk.Frame):
12+
13+
cells = [
14+
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
15+
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
16+
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
17+
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
18+
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
19+
['!', '@', '#', '$', '%', '&', '*', '/', '\'', '.', ',', ';', ':', '?',
20+
'<', '>', '😀', '😋', '😂', '🌞', '🌴', '🍕', '🏳', '♻', '✔', '👍'],
21+
]
22+
23+
def __init__(self, *args, **kwargs):
24+
super().__init__(*args, **kwargs)
25+
26+
self.target = None
27+
self.memory = ''
28+
29+
for y, row in enumerate(self.cells):
30+
for x, item in enumerate(row):
31+
b = tk.Button(self,
32+
text=item,
33+
command=lambda text=item: self.append(text),
34+
font=("Arial", 14),
35+
bg="light green",
36+
fg="blue",
37+
borderwidth=3,
38+
relief="raised")
39+
b.grid(row=y, column=x, sticky='news')
40+
41+
x = tk.Button(self,
42+
text='Space',
43+
command=self.space,
44+
font=("Arial", 14),
45+
bg="light green",
46+
fg="blue",
47+
borderwidth=3,
48+
relief="raised")
49+
x.grid(row=0, column=10, columnspan='4', sticky='news')
50+
51+
x = tk.Button(self,
52+
text='tab',
53+
command=self.tab,
54+
font=("Arial", 14),
55+
bg="light green",
56+
fg="blue",
57+
borderwidth=3,
58+
relief="raised")
59+
x.grid(row=0, column=14, columnspan='3', sticky='news')
60+
61+
x = tk.Button(self,
62+
text='Backspace',
63+
command=self.backspace,
64+
font=("Arial", 14),
65+
bg="light green",
66+
fg="blue",
67+
borderwidth=3,
68+
relief="raised")
69+
x.grid(row=0, column=17, columnspan='3', sticky='news')
70+
71+
x = tk.Button(self,
72+
text='Clear',
73+
command=self.clear,
74+
font=("Arial", 14),
75+
bg="light green",
76+
fg="blue",
77+
borderwidth=3,
78+
relief="raised")
79+
x.grid(row=0, column=20, columnspan='3', sticky='news')
80+
81+
x = tk.Button(self,
82+
text='Hide',
83+
command=self.hide,
84+
font=("Arial", 14),
85+
bg="light green",
86+
fg="blue",
87+
borderwidth=3,
88+
relief="raised")
89+
x.grid(row=0, column=23, columnspan='3', sticky='news')
90+
91+
def get(self):
92+
if self.target:
93+
return self.target.get("1.0", "end-1c")
94+
95+
def append(self, text):
96+
if self.target:
97+
self.target.insert('end', text)
98+
99+
def clear(self):
100+
if self.target:
101+
self.target.delete('1.0', 'end')
102+
103+
def backspace(self):
104+
if self.target:
105+
text = self.get()
106+
text = text[:-1]
107+
self.clear()
108+
self.append(text)
109+
110+
def space(self):
111+
if self.target:
112+
text = self.get()
113+
text = text + " "
114+
self.clear()
115+
self.append(text)
116+
117+
def tab(self): # 5 spaces
118+
if self.target:
119+
text = self.get()
120+
text = text + " "
121+
self.clear()
122+
self.append(text)
123+
124+
def copy(self):
125+
# TODO: copy to clipboad
126+
if self.target:
127+
self.memory = self.get()
128+
self.label['text'] = 'memory: ' + self.memory
129+
print(self.memory)
130+
131+
def paste(self):
132+
# TODO: copy from clipboad
133+
if self.target:
134+
self.append(self.memory)
135+
136+
def show(self, entry):
137+
self.target = entry
138+
139+
self.place(relx=0.5, rely=0.5, anchor='c')
140+
141+
def hide(self):
142+
self.target = None
143+
144+
self.place_forget()
145+
146+
# -------------------------------------------------------
147+
148+
149+
def print_output():
150+
mbox.showinfo("Text Entered",
151+
"Text Entered :\n\n" + text_enter.get('1.0', END))
152+
153+
# firstclick1 = True
154+
# def on_text_enter_click(event):
155+
# """function that gets called whenever entry1 is clicked"""
156+
# global firstclick1
157+
# if firstclick1: # if this is the first time they clicked it
158+
# firstclick1 = False
159+
# text_enter.delete('1.0', "end") # delete all the text in the entry
160+
161+
162+
def des_f1():
163+
f1.destroy()
164+
165+
166+
f1 = Frame(root, height=700, width=1000)
167+
f1.propagate(0)
168+
f1.pack(side='top')
169+
170+
# start1 = Label(f1, text='VIRTUAL', font=("Arial", 100), fg="magenta")
171+
# start1.place(x=250, y=100)
172+
#
173+
# start2 = Label(f1, text='KEYBOARD', font=("Arial", 100), fg="magenta")
174+
# start2.place(x=150, y=300)
175+
176+
c = Canvas(f1, width=1000, height=700)
177+
c.pack()
178+
p1 = PhotoImage(file="Images/keyboard.png")
179+
c.create_image(200, 100, image=p1, anchor=NW)
180+
181+
start1 = Label(f1,
182+
text='VIRTUAL KEYBOARD',
183+
font=("Arial", 50),
184+
fg="magenta",
185+
underline=0)
186+
start1.place(x=150, y=10)
187+
188+
startb = Button(f1,
189+
text="START",
190+
command=des_f1,
191+
font=("Arial", 30),
192+
bg="light green",
193+
fg="blue",
194+
borderwidth=3,
195+
relief="raised")
196+
startb.place(x=180, y=550)
197+
198+
199+
f2 = Frame(root, height=700, width=1000)
200+
f2.propagate(0)
201+
f2.pack(side='top')
202+
203+
keypad = Keypad(root)
204+
205+
start2 = Label(f2, text='ENTER TEXT HERE...', font=("Arial", 40), fg="magenta")
206+
start2.place(x=200, y=460)
207+
208+
text_enter = tk.Text(f2,
209+
height=10,
210+
width=80,
211+
font=("Arial", 15),
212+
bg="light yellow",
213+
fg="brown",
214+
borderwidth=3,
215+
relief="solid")
216+
text_enter.insert(END, 'Enter your text here from virtual keyboard...')
217+
# default line in text area, can be cleared when touched
218+
# text_enter.bind('<FocusIn>', on_text_enter_click)
219+
text_enter.place(x=50, y=10)
220+
221+
keyboardb = Button(f2,
222+
text="KEYBOARD",
223+
command=lambda: keypad.show(text_enter),
224+
font=("Arial", 30),
225+
bg="light green",
226+
fg="blue",
227+
borderwidth=3,
228+
relief="raised")
229+
keyboardb.place(x=100, y=550)
230+
231+
printb = Button(f2,
232+
text="PRINT",
233+
command=print_output,
234+
font=("Arial", 30),
235+
bg="light green",
236+
fg="blue",
237+
borderwidth=3,
238+
relief="raised")
239+
printb.place(x=450, y=550)
240+
241+
242+
def exit_win():
243+
if messagebox.askokcancel("Exit", "Do you want to exit?"):
244+
root.destroy()
245+
246+
247+
exitb = Button(root,
248+
text="EXIT",
249+
command=exit_win,
250+
font=("Arial", 30),
251+
bg="red",
252+
fg="blue",
253+
borderwidth=3,
254+
relief="raised")
255+
exitb.place(x=700, y=550)
256+
257+
258+
root.protocol("WM_DELETE_WINDOW", exit_win)
259+
root.mainloop()

virtual_keyboard/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
libraries used : tkinter
2+
messagebox

0 commit comments

Comments
 (0)