In: Computer Science
import tkinter as tk
import math
window = tk.Tk()
window.title("RSA Encryption/Decryption")
window.geometry("500x500")
#screen.configure(background="black")
#functions
def Modulus():
p = int(p_input1.get())
q = int(q_input1.get())
n = p*q
open_text = tk.Label(text="Keep your Messages Secure", fg =
"white", bg = "blue")
open_text.pack()
Encryp_text = tk.Label(text="Encryption", fg="white",
bg="red")
Encryp_text.place(x=200, y=35)
Decryp_text = tk.Label(text="Decryption", fg="white",
bg="green")
Decryp_text.place(x=200, y=270)
p_input=tk.Label(text="Enter the value of P: ")
p_input.place(x=10, y=58)
p_input1=tk.Entry()
p_input1.place(x = 130, y=58)
q_input=tk.Label(text="Enter the value of q:")
q_input.place(x=10, y=78)
q_input1=tk.Entry()
q_input1.place(x = 130, y=78)
mod = tk.Label(text= "RSA Modulus(n)is: ",command = Modulus)
mod.place(x=10, y=100)
window.mainloop()
i'm not able to get the result which is the value of n. can you please help with this?
For this program, the control with the name mod should not be a label, it should be a button which must be created as
mod = tk.Button(text= "RSA Modulus(n)is: ",command = Modulus)
The button control has command argument
To display the result, i.e value of n, a label is created inside the Modulus function to which value of n is assigned after converting n to string.
mod_output=tk.Label(text=str(n))
mod_output.place(x=135, y=100)
The complete program and out put screen is given for your reference.
import tkinter as tk
import math
window = tk.Tk()
window.title("RSA Encryption/Decryption")
window.geometry("500x500")
#screen.configure(background="black")
#functions
def Modulus():
p = int(p_input1.get())
q = int(q_input1.get())
n = p*q
mod_output=tk.Label(text=str(n))
mod_output.place(x=135, y=100)
open_text = tk.Label(text="Keep your Messages Secure", fg =
"white", bg = "blue")
open_text.pack()
Encryp_text = tk.Label(text="Encryption", fg="white",
bg="red")
Encryp_text.place(x=200, y=35)
Decryp_text = tk.Label(text="Decryption", fg="white",
bg="green")
Decryp_text.place(x=200, y=270)
p_input=tk.Label(text="Enter the value of P: ")
p_input.place(x=10, y=58)
p_input1=tk.Entry()
p_input1.place(x = 130, y=58)
q_input=tk.Label(text="Enter the value of q:")
q_input.place(x=10, y=78)
q_input1=tk.Entry()
q_input1.place(x = 130, y=78)
mod = tk.Button(text= "RSA Modulus(n)is: ",command = Modulus)
mod.place(x=10, y=100)
window.mainloop()
PROGRAM
import tkinter as tk
import math
window = tk.Tk()
window.title("RSA Encryption/Decryption")
window.geometry("500x500")
#screen.configure(background="black")
#functions
def Modulus():
p = int(p_input1.get())
q = int(q_input1.get())
n = p*q
mod_output=tk.Label(text=str(n))
mod_output.place(x=135, y=100)
open_text = tk.Label(text="Keep your Messages Secure", fg = "white", bg = "blue")
open_text.pack()
Encryp_text = tk.Label(text="Encryption", fg="white", bg="red")
Encryp_text.place(x=200, y=35)
Decryp_text = tk.Label(text="Decryption", fg="white", bg="green")
Decryp_text.place(x=200, y=270)
p_input=tk.Label(text="Enter the value of P: ")
p_input.place(x=10, y=58)
p_input1=tk.Entry()
p_input1.place(x = 130, y=58)
q_input=tk.Label(text="Enter the value of q:")
q_input.place(x=10, y=78)
q_input1=tk.Entry()
q_input1.place(x = 130, y=78)
mod = tk.Button(text= "RSA Modulus(n)is: ",command = Modulus)
mod.place(x=10, y=100)
window.mainloop()
OUTPUT SCREEN