Skip to content

Commit

Permalink
Merge pull request #2081 from NitkarshChourasia/testing
Browse files Browse the repository at this point in the history
add: Improve programs and feature updates.
  • Loading branch information
geekcomputers authored Jan 9, 2024
2 parents 01311d8 + 641e756 commit 0c73909
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 139 deletions.
5 changes: 0 additions & 5 deletions 12.py

This file was deleted.

3 changes: 0 additions & 3 deletions 56

This file was deleted.

9 changes: 0 additions & 9 deletions Count the Number of Each Vowel

This file was deleted.

35 changes: 0 additions & 35 deletions addition.py

This file was deleted.

30 changes: 28 additions & 2 deletions encrypter-decrypter-gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ def __init__(self, parent):
self.parent = parent
# ========== Data Key ==========
self.data_dic = {
"A": "Q",
"B": "W",
"C": "E",
"D": "R",
"E": "T",
"F": "Y",
"G": "U",
"H": "I",
"I": "O",
"J": "P",
"K": "A",
"L": "S",
"M": "D",
"N": "F",
"O": "G",
"P": "H",
"Q": "J",
"R": "K",
"S": "L",
"T": "Z",
"U": "X",
"V": "C",
"W": "V",
"X": "B",
"Y": "N",
"Z": "M",
"a": "q",
"b": "w",
"c": "e",
Expand Down Expand Up @@ -199,7 +225,7 @@ def backend_work(self, todo, text_coming):
try:
text_coming = str(
text_coming
).lower() # <----- Lowering the letters as dic in lower letter
) # <----- Lowering the letters as dic in lower letter
for word in text_coming:
for key, value in self.data_dic.items():
if word == key:
Expand All @@ -212,7 +238,7 @@ def backend_work(self, todo, text_coming):
return text_to_return
elif todo == "Decrypt":
try:
text_coming = str(text_coming).lower()
text_coming = str(text_coming)
for word in text_coming:
for key, value in self.data_dic.items():
if word == value:
Expand Down
263 changes: 263 additions & 0 deletions encrypter_decrypter_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
# ==================== Importing Libraries ====================
# =============================================================
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showerror
from tkinter.scrolledtext import ScrolledText

# =============================================================


class Main(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title("Alphacrypter")
# ----- Setting Geometry -----
self.geometry_settings()

def geometry_settings(self):
_com_scr_w = self.winfo_screenwidth()
_com_scr_h = self.winfo_screenheight()
_my_w = 300
_my_h = 450
# ----- Now Getting X and Y Coordinates
_x = int(_com_scr_w / 2 - _my_w / 2)
_y = int(_com_scr_h / 2 - _my_h / 2)
_geo_string = str(_my_w) + "x" + str(_my_h) + "+" + str(_x) + "+" + str(_y)
self.geometry(_geo_string)
# ----- Geometry Setting Completed Now Disabling Resize Screen Button -----
self.resizable(width=False, height=False)


class Notebook:
def __init__(self, parent):
self.parent = parent
# ========== Data Key ==========
self.data_dic = {
"A": "Q",
"B": "W",
"C": "E",
"D": "R",
"E": "T",
"F": "Y",
"G": "U",
"H": "I",
"I": "O",
"J": "P",
"K": "A",
"L": "S",
"M": "D",
"N": "F",
"O": "G",
"P": "H",
"Q": "J",
"R": "K",
"S": "L",
"T": "Z",
"U": "X",
"V": "C",
"W": "V",
"X": "B",
"Y": "N",
"Z": "M",
"a": "q",
"b": "w",
"c": "e",
"d": "r",
"e": "t",
"f": "y",
"g": "u",
"h": "i",
"i": "o",
"j": "p",
"k": "a",
"l": "s",
"m": "d",
"n": "f",
"o": "g",
"p": "h",
"q": "j",
"r": "k",
"s": "l",
"t": "z",
"u": "x",
"v": "c",
"w": "v",
"x": "b",
"y": "n",
"z": "m",
"1": "_",
"2": "-",
"3": "|",
"4": "?",
"5": "*",
"6": "!",
"7": "@",
"8": "#",
"9": "$",
"0": "~",
".": "/",
",": "+",
" ": "&",
}
# ==============================
# ----- Notebook With Two Pages -----
self.nb = ttk.Notebook(self.parent)
self.page1 = ttk.Frame(self.nb)
self.page2 = ttk.Frame(self.nb)
self.nb.add(self.page1, text="Encrypt The Words")
self.nb.add(self.page2, text="Decrypt The Words")
self.nb.pack(expand=True, fill="both")
# ----- LabelFrames -----
self.page1_main_label = ttk.LabelFrame(
self.page1, text="Encrypt Any Text"
) # <----- Page1 LabelFrame1
self.page1_main_label.grid(row=0, column=0, pady=20, padx=2, ipadx=20)
self.page1_output_label = ttk.LabelFrame(self.page1, text="Decrypted Text")
self.page1_output_label.grid(row=1, column=0, pady=10, padx=2)

self.page2_main_label = ttk.LabelFrame(
self.page2, text="Decrypt Any Text"
) # <----- Page1 LabelFrame1
self.page2_main_label.grid(row=0, column=0, pady=20, padx=2, ipadx=20)
self.page2_output_label = ttk.LabelFrame(self.page2, text="Real Text")
self.page2_output_label.grid(row=1, column=0, pady=10, padx=2)
# <---Scrolled Text Global
self.decrypted_text_box = ScrolledText(
self.page1_output_label, width=30, height=5, state="normal"
)
self.decrypted_text_box.grid(row=1, column=0, padx=2, pady=10)

self.text_box = ScrolledText(
self.page2_output_label, width=30, height=5, state="normal"
)
self.text_box.grid(row=1, column=0, padx=2, pady=10)
# ----- Variables -----
self.user_text = tk.StringVar()
self.decrypted_user_text = tk.StringVar()

self.user_text2 = tk.StringVar()
self.real_text = tk.StringVar()
# ----- Getting Inside Page1 -----
self.page1_inside()
self.page2_inside()

def page1_inside(self):
style = ttk.Style()
user_text_label = ttk.Label(
self.page1_main_label, text="Enter Your Text Here : ", font=("", 14)
)
user_text_label.grid(row=0, column=0, pady=10)
user_entry_box = ttk.Entry(
self.page1_main_label, width=35, textvariable=self.user_text
)
user_entry_box.grid(row=1, column=0)
style.configure(
"TButton",
foreground="black",
background="white",
relief="groove",
font=("", 12),
)
encrypt_btn = ttk.Button(
self.page1_main_label,
text="Encrypt Text",
style="TButton",
command=self.encrypt_now,
)
encrypt_btn.grid(row=2, column=0, pady=15)

# ---------- Page1 Button Binding Function ----------

def encrypt_now(self):
user_text = self.user_text.get()
if user_text == "":
showerror(
"Nothing Found", "Please Enter Something In Entry Box To Encrypt...!"
)
return
else:
self.decrypted_user_text = self.backend_work("Encrypt", user_text)
self.decrypted_text_box.insert(tk.INSERT, self.decrypted_user_text, tk.END)

# --------------------------------------------------Binding Functions of Page1 End Here
# Page2 ------------------>
def page2_inside(self):
style = ttk.Style()
user_text_label = ttk.Label(
self.page2_main_label, text="Enter Decrypted Text Here : ", font=("", 14)
)
user_text_label.grid(row=0, column=0, pady=10)
user_entry_box = ttk.Entry(
self.page2_main_label, width=35, textvariable=self.user_text2
)
user_entry_box.grid(row=1, column=0)
style.configure(
"TButton",
foreground="black",
background="white",
relief="groove",
font=("", 12),
)
encrypt_btn = ttk.Button(
self.page2_main_label,
text="Decrypt Text",
style="TButton",
command=self.decrypt_now,
)
encrypt_btn.grid(row=2, column=0, pady=15)
# ---------- Page1 Button Binding Function ----------

def decrypt_now(self):
user_text = self.user_text2.get()
if user_text == "":
showerror(
"Nothing Found", "Please Enter Something In Entry Box To Encrypt...!"
)
return
else:
self.real_text = self.backend_work("Decrypt", user_text)
self.text_box.insert(tk.INSERT, self.real_text, tk.END)

def backend_work(self, todo, text_coming):
text_to_return = ""
if todo == "Encrypt":
try:
text_coming = str(
text_coming
) # <----- Lowering the letters as dic in lower letter
for word in text_coming:
for key, value in self.data_dic.items():
if word == key:
# print(word, " : ", key)
text_to_return += value

except ValueError:
showerror("Unknown", "Something Went Wrong, Please Restart Application")

return text_to_return
elif todo == "Decrypt":
try:
text_coming = str(text_coming)
for word in text_coming:
for key, value in self.data_dic.items():
if word == value:
text_to_return += key

except ValueError:
showerror("Unknown", "Something Went Wrong, Please Restart Application")

return text_to_return

else:
showerror("No Function", "Function Could not get what to do...!")


# =============================================================
# ==================== Classes End Here ... ! =================


if __name__ == "__main__":
run = Main()
Notebook(run)
run.mainloop()
9 changes: 0 additions & 9 deletions even and odd.py

This file was deleted.

5 changes: 0 additions & 5 deletions even.py

This file was deleted.

9 changes: 0 additions & 9 deletions factor.py

This file was deleted.

Loading

0 comments on commit 0c73909

Please sign in to comment.