-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorseCode COnverter.py
162 lines (133 loc) · 3.5 KB
/
morseCode COnverter.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from tkinter import *
from functools import partial
import tkinter.messagebox as tmessage
win=Tk()
codes = {
'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': '--..',
'1': '.----',
'2': '..---',
'3': '...--',
'4': '....-',
'5': '.....',
'6': '-....',
'7': '--...',
'8': '---..',
'9': '----.',
'0': '-----',
', ': '--..--',
'.': '.-.-.-',
'?': '..--..',
'/': '-..-.',
'-': '-....-',
'(': '-.--.',
')': '-.--.-',
}
#Save Confirmation Function
def foolFunction():
show=tmessage.showinfo("Confirmation","Your File Is Saved In Your Device in the name of %s"%x)
#Random name is taken to save the files with Differnet name
from random import choice
name = ["one", "two", "three", "foure", "five", "sixerer", "dosfho", "ishfak", "momin", "ali", "chand", "gazal",
"python", "tkihnter", "label"]
x = choice(name)
#Auto Save Function Is Being Performed
def saveFunction(something,some):
newFile=open("%s.txt"%x,"w")
text=something+"="+some
newFile.write(text)
#MorseCode To Text
def sssum(label,x2):
n2 = (x2.get())
word=n2
word += ' '
decipher = ''
citext = ''
for letter in word:
if (letter != ' '):
i = 0
citext += letter
else:
i += 1
if i == 2:
decipher += ' '
else:
decipher += list(codes.keys())[
list(codes.values()).index(citext)]
citext = ''
label.config(text=decipher)
saveFunction(word,decipher)
return decipher
#Text to MorseCode Converter Function
def sum(label,x1):
n1=(x1.get())
code = n1
word = code.upper()
a = ""
for i in word:
if (i !=" "):
a += codes[i]+" "
else:
a += " "
label.config(text=a)
saveFunction(word,a)
return a
#GUI Building
l0=Label(win,text="Welcome to the MorseCode Converter",fg="BLue",bg="Violet" )
l0.grid(row=2,column=2)
l1=Label(win,text="Enter the text to be encrypted: ",fg="BLue",bg="Violet")
l1.grid(row=3,column=0)
l2=Label(win,text="Enter the MorseCode to be decyphyered: ",fg="BLue",bg="Violet")
l2.grid(row=5,column=0)
label =Label(win)
win.geometry("550x100")
label.grid(row=6,column=2)
x1=StringVar()
x2=StringVar()
e1=Entry(win,textvariable=x1)
e2=Entry(win,textvariable=x2)
win.title("MORSECODE CONVERTER")
e1.grid(row=3,column=2)
e2.grid(row=5,column=2)
win.configure(background="Blue")
sum=partial(sum,label,x1)
#Button Is Decleared
button=Button(win,text="Encrypt",command=sum,fg="BLue",bg="Violet")
sssum=partial(sssum,label,x2)
button2=Button(win,text="Decrypt",command=sssum,fg="BLue",bg="Violet")
button2.grid(row=5,column=3)
button.grid(row=3,column=3)
#MenuBar Layout Design
mymenu=Menu(win)
m1=Menu(mymenu,tearoff=0)
m1.add_command(label="Save",command=foolFunction)
m1.add_command(label="Exit",command=quit)
m1.add_separator()
win.config(menu=mymenu)
mymenu.add_cascade(label="File",menu=m1)
#Last Packing Of the GUI LAyout
win.mainloop()