tkinter - Having trouble with this method of changing and showing a new window in python -
i having quite trouble using classes in python. first code used in changing , showing new window works cluttered decided use class. there might wrong in code. can atleast see it? thank you. hoping fast response.
import random, sys, os, rabinmiller, cryptomath tkinter import * import tkinter tk pil import image, imagetk tkinter.filedialog import askopenfile class mainframe(tk.tk): def __init__(self, *args, **kwargs): tk.tk.__init__(self, *args, **kwargs) container = tk.frame(self) #frame1.title("rsa cryptosystem") #frame1.config(bg="black") container.columnconfigure(0, weight=1) container.rowconfigure(0, weight=1) self.frames = {} f in (startpage, decryptionpage, encryptionpage, makekeypage): frame = f(container, self) self.frames[f] = frame frame.grid(row=0, column=0, sticky=(n, w, e, s)) self.show_frame(startpage) def show_frame(self, cont): frame = self.frames[cont] frame.tkraise() class startpage(tk.frame): def __init__(self, parent, controller): tk.frame.__init__(self,parent) image4 = image.open("rsa cryptosystem logo.jpg") photo4 = imagetk.photoimage(image4) label1 = tk.label(self, image=photo4) label1.grid(column=1, row=1, columnspan=3, padx=5, pady=5) label1.image = photo4 image1 = image.open("make key.jpg") photo1 = imagetk.photoimage(image1) image2 = image.open("encryption button.jpg") photo2 = imagetk.photoimage(image2) image3 = image.open("decryption button.jpg") photo3 = imagetk.photoimage(image3) button1 = tk.button(self, compound=top, command=lambda: controller.show_frame(makekeypage), width=338, height=338, image=photo1) button1.grid(column=1, row=2, sticky=s, rowspan=2, padx=5, pady=5) button1.image = photo1 button2 = tk.button(self, compound=top, command=lambda: controller.show_frame(encryptionpage), width=525, height=150, image=photo2) button2.grid(column=2, row=2, sticky=(w, e), columnspan=2, padx=5, pady=5) button2.image = photo2 button3 = tk.button(self, compound=top, command=lambda: controller.show_frame(decryptionpage), width=525, height=150, image=photo3) button3.grid(column=2, row=3, sticky=(w, e), columnspan=2, padx=5, pady=5) button3.image = photo3 class decryptionpage(tk.frame): def __init__(self, parent, controller): textframe1 = tk.text(self, width=70, height=32).grid(column=3, row=2, rowspan=3, padx=5, pady=5, sticky=(s, e)) image5 = image.open("insert private key.jpg") photo5 = imagetk.photoimage(image5) image6 = image.open("insert encrypted text.jpg") photo6 = imagetk.photoimage(image6) image7 = image.open("decrypt.jpg") photo7 = imagetk.photoimage(image7) button4 = tk.button(self, width=338, height=80, image=photo5, command=open_file) button4.grid(column=1, row=2,columnspan=2, sticky=n) button4.image = photo5 button5 = tk.button(self, width=338, height=80, image=photo6, command=open_file) button5.grid(column=1, row=3, columnspan=2, sticky=n) button5.image = photo6 button6 = tk.button(self, text="back", command=lambda: controller.show_frame(startpage)) button6.grid(column=1, row=1, padx=5, pady=5, sticky=w) button7 = tk.button(self, width=338, height=338, image=photo7) button7.grid(column=1, row=4, padx=5, pady=5, columnspan=2, sticky=s) button7.image = photo7 class encryptionpage(tk.frame): def __init__(self, parent, controller): textframe2 = tk.text(self, width=70, height=32).grid(column=3, row=2, columnspan=2, rowspan=3, padx=5, pady=5, sticky=(s, e)) image8 = image.open("insert public key.jpg") photo8 = imagetk.photoimage(image8) image9 = image.open("encrypt.jpg") photo9 = imagetk.photoimage(image9) button8 = tk.button(self, width=338, height=80, image=photo8, command=open_file) button8.grid(column=1, row=2,columnspan=2, sticky=n) button8.image = photo8 button10 = tk.button(self, text="back", command=lambda: controller.show_frame(startpage)) button10.grid(column=1, row=1, padx=5, pady=5, sticky=w) button9 = tk.button(self, width=338, height=338, image=photo9) button9.grid(column=1, row=4, padx=5, pady=5, columnspan=2, sticky=s) button9.image = photo9 receivename = stringvar() receivename_entry = tk.entry(self, width=85, textvariable=receivename).grid(column=4, row=1, padx=5, pady=5, sticky=(w, e)) label4 = tk.label(self, text="to: ").grid(column=3, row=1, padx=5, pady=5, sticky=w) class makekeypage(tk.frame): def __init__(self, parent, controller): keyname = stringvar() phone = stringvar() keyname_entry = tk.entry(self, width=15, textvariable=keyname) keyname_entry.grid(column=2, row=2, sticky=e, padx=5, pady=5) label2 = tk.label(self, text="key name: ") label2.grid(column=1, row=2, sticky=w, padx=5, pady=5) label3 = tk.label(self, text="key type: ") label3.grid(column=1, row=3, sticky=w, padx=5, pady=5) button12 = tk.button(self, text="back", command=lambda: controller.show_frame(startpage)).grid(column=1, row=1, padx=5, pady=5, sticky=w) prime = tk.radiobutton(self, text="prime", variable=phone, value='prime').grid(column=1, row=4, sticky=(w, e)) luckyprime = tk.radiobutton(self, text="lucky prime", variable=phone, value='luckyprime').grid(column=2, row=4, sticky=(w, e)) button11 = tk.button(self, text="generate keys").grid(column=1, row=5, columnspan=2, sticky=(w, e)) app = mainframe() app.mainloop()
Comments
Post a Comment