Tkinter自动停止

时间:2016-02-26 00:40:26

标签: python tkinter

所以,我之前做了一个加密程序,我想用Tkinter给它一个UI。我正在做的是使用三个输入字段和一个按钮;第一个字段用于明文,加密的结果放在另外两个字段中。该过程由底部的按钮激活。函数crypt()返回一个带有加密字符串和密钥的数组。

以下是源代码的一部分:

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()

问题在于,无论出于何种原因,crypt会自动运行并将['','']打印到控制台。

0 个答案:

没有答案