Skip to content

Commit 0b048ab

Browse files
committed
Added Virtual keyboard in Python Scripts
1 parent 26e596c commit 0b048ab

File tree

11 files changed

+221
-0
lines changed

11 files changed

+221
-0
lines changed

Python/Virtual Keyboard/Images/1.jpg

80.9 KB
Loading

Python/Virtual Keyboard/Images/2.jpg

66.3 KB
Loading

Python/Virtual Keyboard/Images/3.jpg

145 KB
Loading

Python/Virtual Keyboard/Images/4.jpg

152 KB
Loading

Python/Virtual Keyboard/Images/5.jpg

165 KB
Loading

Python/Virtual Keyboard/Images/6.jpg

153 KB
Loading

Python/Virtual Keyboard/Images/7.jpg

139 KB
Loading
13.1 KB
Loading

Python/Virtual Keyboard/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
30+
# SCREENSHOTS :
31+
32+
****
33+
34+
<p align="center">
35+
<img width = 800 src="Images/1.jpg" /><br>
36+
<img width = 800 src="Images/2.jpg" /><br>
37+
<img width = 800 src="Images/3.jpg" /><br>
38+
<img width = 800 src="Images/4.jpg" /><br>
39+
<img width = 800 src="Images/5.jpg" /><br>
40+
<img width = 800 src="Images/6.jpg" /><br>
41+
<img width = 800 src="Images/7.jpg" /><br>
42+
</p>
43+
44+
****
45+
46+
# Below is the link to video showing how script works :
47+
https://user-images.githubusercontent.com/57003737/123204915-9ef6db00-d4d6-11eb-8e67-0c7901e9d1a0.mp4
48+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
libraries used : tkinter
2+
messagebox
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
import tkinter.messagebox as mbox
4+
import tkinter as tk
5+
6+
7+
root = Tk()
8+
root.title("Virtual Keyboard")
9+
root.geometry('1000x700')
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', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
16+
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M','N', 'O', 'P', 'Q','R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
17+
['!', '@', '#', '$', '%', '&', '*', '/', '\'', '.', ',', ';', ':', '?', '<', '>','😀','😋','😂','🌞','🌴','🍕','🏳', '♻', '✔', '👍'],
18+
]
19+
20+
def __init__(self, *args, **kwargs):
21+
super().__init__(*args, **kwargs)
22+
23+
self.target = None
24+
self.memory = ''
25+
26+
for y, row in enumerate(self.cells):
27+
for x, item in enumerate(row):
28+
b = tk.Button(self, text=item, command=lambda text=item:self.append(text),font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
29+
b.grid(row=y, column=x, sticky='news')
30+
31+
x = tk.Button(self, text='Space', command=self.space,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
32+
x.grid(row=0, column=10, columnspan='4', sticky='news')
33+
34+
x = tk.Button(self, text='tab', command=self.tab,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
35+
x.grid(row=0, column=14, columnspan='3', sticky='news')
36+
37+
x = tk.Button(self, text='Backspace', command=self.backspace,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
38+
x.grid(row=0, column=17,columnspan='3', sticky='news')
39+
40+
x = tk.Button(self, text='Clear', command=self.clear,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
41+
x.grid(row=0, column=20, columnspan='3', sticky='news')
42+
43+
x = tk.Button(self, text='Hide', command=self.hide,font=("Arial", 14), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
44+
x.grid(row=0, column=23, columnspan='3', sticky='news')
45+
46+
47+
def get(self):
48+
if self.target:
49+
return self.target.get("1.0", "end-1c")
50+
51+
def append(self, text):
52+
if self.target:
53+
self.target.insert('end', text)
54+
55+
def clear(self):
56+
if self.target:
57+
self.target.delete('1.0', 'end')
58+
59+
def backspace(self):
60+
if self.target:
61+
text = self.get()
62+
text = text[:-1]
63+
self.clear()
64+
self.append(text)
65+
66+
def space(self):
67+
if self.target:
68+
text = self.get()
69+
text = text + " "
70+
self.clear()
71+
self.append(text)
72+
73+
def tab(self): # 5 spaces
74+
if self.target:
75+
text = self.get()
76+
text = text + " "
77+
self.clear()
78+
self.append(text)
79+
80+
def copy(self):
81+
#TODO: copy to clipboad
82+
if self.target:
83+
self.memory = self.get()
84+
self.label['text'] = 'memory: ' + self.memory
85+
print(self.memory)
86+
87+
def paste(self):
88+
#TODO: copy from clipboad
89+
if self.target:
90+
self.append(self.memory)
91+
92+
def show(self, entry):
93+
self.target = entry
94+
95+
self.place(relx=0.5, rely=0.5, anchor='c')
96+
97+
def hide(self):
98+
self.target = None
99+
100+
self.place_forget()
101+
102+
#-------------------------------------------------------
103+
104+
def print_output():
105+
mbox.showinfo("Text Entered", "Text Entered :\n\n" + text_enter.get('1.0',END))
106+
107+
# firstclick1 = True
108+
# def on_text_enter_click(event):
109+
# """function that gets called whenever entry1 is clicked"""
110+
# global firstclick1
111+
# if firstclick1: # if this is the first time they clicked it
112+
# firstclick1 = False
113+
# text_enter.delete('1.0', "end") # delete all the text in the entry
114+
115+
def des_f1():
116+
f1.destroy()
117+
118+
119+
f1 = Frame(root, height=700, width=1000)
120+
f1.propagate(0)
121+
f1.pack(side='top')
122+
123+
# start1 = Label(f1, text='VIRTUAL', font=("Arial", 100), fg="magenta")
124+
# start1.place(x=250, y=100)
125+
#
126+
# start2 = Label(f1, text='KEYBOARD', font=("Arial", 100), fg="magenta")
127+
# start2.place(x=150, y=300)
128+
129+
c = Canvas(f1, width=1000, height=700)
130+
c.pack()
131+
p1 = PhotoImage(file='Images/keyboard.gif')
132+
c.create_image(200, 100, image=p1, anchor=NW)
133+
134+
start1 = Label(f1, text='VIRTUAL KEYBOARD', font=("Arial", 50), fg="magenta", underline = 0)
135+
start1.place(x=150, y=10)
136+
137+
startb = Button(f1, text="START",command=des_f1,font=("Arial", 30), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
138+
startb.place(x = 180 , y =550 )
139+
140+
141+
f2 = Frame(root, height=700, width=1000)
142+
f2.propagate(0)
143+
f2.pack(side='top')
144+
145+
keypad = Keypad(root)
146+
147+
start2 = Label(f2, text='ENTER TEXT HERE...', font=("Arial", 40), fg="magenta")
148+
start2.place(x=200, y=460)
149+
150+
text_enter = tk.Text(f2, height=10, width=80, font=("Arial", 15), bg="light yellow", fg="brown",borderwidth=3, relief="solid")
151+
text_enter.insert(END, 'Enter your text here from virtual keyboard...') # default line in text area, can be cleared when touched
152+
# text_enter.bind('<FocusIn>', on_text_enter_click)
153+
text_enter.place(x=50, y=10)
154+
155+
keyboardb = Button(f2, text="KEYBOARD",command=lambda:keypad.show(text_enter),font=("Arial", 30), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
156+
keyboardb.place(x =100 , y =550 )
157+
158+
printb = Button(f2, text="PRINT",command=print_output,font=("Arial", 30), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
159+
printb.place(x =450 , y =550 )
160+
161+
def exit_win():
162+
if messagebox.askokcancel("Exit", "Do you want to exit?"):
163+
root.destroy()
164+
165+
166+
exitb = Button(root, text="EXIT",command=exit_win,font=("Arial", 30), bg = "red", fg = "blue", borderwidth=3, relief="raised")
167+
exitb.place(x =700 , y =550 )
168+
169+
170+
root.protocol("WM_DELETE_WINDOW", exit_win)
171+
root.mainloop()

0 commit comments

Comments
 (0)