0

So, I made an encryption program a while back, and I want to give it a UI using Tkinter. What I'm doing is using three entry fields and a button; the first field is for the plaintext, and the result of encrypting it is put into the other two fields. The process is activated by a button at the bottom. The function crypt() returns an array with the crypted string and key.

Here's a part of the source code:

class App(Frame):
    def createWidgets(self):
        self.quitButton = Button(self, text='Quit', command= self.quit())            
        self.quitButton.grid(row = 5, column = 2)
        self.crypter_lab = Label(self, text = "Text to Encrypt").grid(row = 0, column = 0)
        self.to_crypt = Entry(self)
        self.to_crypt.grid(row = 0, column = 1)
        self.crpt_lab = Label(self, text = "Crypted Text")
        self.crpt_lab.grid(row = 1, column = 0) 
        self.outcrpt = Entry(self, state = DISABLED)
        self.outcrpt.grid(row = 1, column = 1)
        self.key_lab = Label(self, text = "Encryption Key")
        self.key_lab.grid(row = 2, column = 0) 
        self.outkey = Entry(self, state = DISABLED)
        self.outkey.grid(row = 2, column = 1)
        def return_to_forms(self):
            result = crypt(self.to_crypt.get())
            self.outcrpt.insert(0,result[0])
            self.outkey.insert(0,result[1])
            print(result)
        self.cryptbut = Button(self, text = "Encrypt", command = return_to_forms(self))
        self.cryptbut.grid(row = 3, column = 1)

    def __init__(self, master = None):
        Frame.__init__(self,master)
        self.grid()
        self.createWidgets()



application = App()
application.master.title('Crypter')
application.mainloop()

The issue is that for whatever reason, crypt runs automatically and prints ['',''] to the console.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
TheRniz
  • 53
  • 2
  • 10
  • `command=lambda: return_to_forms(self)` should solve this. Without hiding inside a `lambda`, `return_to_forms(self)` is called immediately in that line. – gil Feb 26 '16 at 01:24
  • THANK YOU! I wouldn't know about that stuff; I'm not the biggest fan of functional programming. – TheRniz Feb 26 '16 at 03:15

0 Answers0