Tkinter回调Traceback中的异常(最近一次调用为最新)

时间:2019-09-29 17:36:04

标签: python python-3.x tkinter

我正在尝试使用email_address_entry值,但遇到此错误。我想使用sign_up_frame对象的email_address_entry值。

在Tkinter回调中获取此异常:

  

回溯(最近通话最近一次):

     

文件“ C:\ Program Files(x86)\ Python37-32 \ lib \ tkinter__init __。py”,   第1705行,在致电       返回self.func(* args)

     

文件“ D:/ Boring college / PyProject / MCB2 / sign_up_1.py”,第140行,在   signup_button_click       self.ans_entry.get(),send_email()))

     

文件“ D:/ Boring college / PyProject / MCB2 / sign_up_1.py”,第154行,在   发送电子邮件       email_id = sign_up_frame.get_email()

     

文件“ D:/ Boring college / PyProject / MCB2 / sign_up_1.py”,第77行,在   get_email       mail = self.email_address_entry.get()

     

文件“ C:\ Program Files(x86)\ Python37-32 \ lib \ tkinter__init __。py”,   2682行,进入       返回self.tk.call(self._w,'get')   _tkinter.TclError:无效的命令名称“。!frame2。!entry”

我的代码如下:

from tkinter import*
from tkinter.ttk import*
from sqlite3 import*
from tkinter import messagebox
import Login_Page


class SignUp(Tk):
    def __init__(self, *args, **kwargs):
        Tk.__init__(self, *args, **kwargs)

        self.title('Contact Book')
        self.geometry('500x400')

        self.style = Style()
        self.style.configure('Header.TFrame', background='Blue')

        self.header_frame = Frame(self, style='Header.TFrame')
        self.header_frame.pack(side=TOP, fill=X)

        self.style.configure('Header.TLabel', background='Blue', foreground='White', font=(NONE,20))

        self.header_label = Label(self.header_frame, style='Header.TLabel', text='Sign Up')
        self.header_label.pack(pady=10)

        self.content_frame = Frame(self)
        self.content_frame.pack(side=TOP, fill=Y, pady=15)

        self.style.configure('Content.TLabel', foreground='Black', font=(NONE, 15))
        self.style.configure('Content.TEntry', foreground='Black', font=(NONE, 15))

        self.email_address_label = Label(self.content_frame, style='Content.TLabel', text='Emailaddress:')
        self.email_address_label.grid(row=0, column=0, pady=8)

        self.email_address_entry = Entry(self.content_frame, style='Content.TEntry', width=30)
        self.email_address_entry.grid(row=0, column=1, padx=5, pady=8)

        self.username_label = Label(self.content_frame, style='Content.TLabel', text='Username:')
        self.username_label.grid(row=1, column=0, pady=8)

        self.username_entry = Entry(self.content_frame, style='Content.TEntry', width=30)
        self.username_entry.grid(row=1, column=1, padx=5, pady=8)

        self.password_label = Label(self.content_frame, style='Content.TLabel', text='Enter Password:')
        self.password_label.grid(row=2, column=0, pady=8)

        self.password_entry = Entry(self.content_frame, style='Content.TEntry', show='*', width=30)
        self.password_entry.grid(row=2, column=1, pady=8, padx=5)

        self.renter_password_label = Label(self.content_frame, style='Content.TLabel', text='Re-Enter Password:')
        self.renter_password_label.grid(row=3, column=0, pady=8)

        self.renter_password_entry = Entry(self.content_frame, style='Content.TEntry', show='*', width=30)
        self.renter_password_entry.grid(row=3, column=1, pady=8, padx=5)

        self.style.configure('SUW.TButton', foreground='Blue')

        self.submit_button = Button(self.content_frame, style='SUW.TButton', text='Submit', width=15,
                                command=self.submit_click)
        self.submit_button.grid(row=4, column=1, pady=20)

    def submit_click(self):
        if self.password_entry.get() == self.renter_password_entry.get():
            con = connect('AppDatabase.db')
            cur = con.cursor()
            cur.execute("""insert into LoginData (Username, Password, Email) values('{0}', '{1}', 
                       '{2}')""".format(self.username_entry.get(), self.password_entry.get(),
                                        self.email_address_entry.get()))
            messagebox.showinfo('Status', 'The Information has been inserted')
            con.commit()
            con.close()
            self.destroy()
        else:
            messagebox.showerror('Invalid', 'Password does not match')

    def get_email(self):
        mail = self.email_address_entry.get()
        return mail


class SafetyQuestion(Tk):
    def __init__(self, *args, **kwargs):
        Tk.__init__(self, *args, **kwargs)

        self.title("Contact Book")
        self.geometry('500x400')

        self.style = Style()
        self.style.configure('Head.TFrame', background='Blue')

        self.head_frame = Frame(self, style='Head.TFrame')
        self.head_frame.pack(side=TOP, fill=X)

        self.style.configure('Head.TLabel', foreground='White', background='Blue', font=(NONE, 15))

        self.head_label = Label(self.head_frame, text='Select one of the following Question:',
                            style='Head.TLabel')
        self.head_label.pack(pady=3)

        self.val = StringVar()
        # val.set('Empty')

        self.r1 = Radiobutton(self, text='What is your nickname?', variable=self.val, value='What is your nickname?')
        self.r1.pack(anchor=W, pady=10, padx=10)
        self.r2 = Radiobutton(self, text='What is the name of your pet?', variable=self.val,
                          value='What is the name of your pet?')
        self.r2.pack(anchor=W, pady=10, padx=10)
        self.r3 = Radiobutton(self, text='What is your favourite food?', variable=self.val,
                          value='What is your favourite food?')
        self.r3.pack(anchor=W, pady=10, padx=10)
        self.r4 = Radiobutton(self, text='What ia your favourite Bike?', variable=self.val,
                          value='What ia your favourite Bike?')
        self.r4.pack(anchor=W, pady=10, padx=10)

        self.answer_frame = Frame(self, style='Head.TFrame')
        self.answer_frame.pack(side=BOTTOM, fill=X)

        self.style.configure('Ans.TLabel', foreground='White', background='Blue', font=(NONE, 12))

        self.ans_label = Label(self.answer_frame, text='Answer:', style='Ans.TLabel')
        self.ans_label.grid(row=0, column=0, pady=2)

        self.style.configure('Ans.TEntry', foreground='Red', font=(NONE, 12))

        self.ans_entry = Entry(self.answer_frame, style='Ans.TEntry', width=25)
        self.ans_entry.grid(row=0, column=1, pady=2)

        self.style.configure('Ans.TButton', forefround='Blue', font=(NONE, 12))

        self.ans_sub_button = Button(self.answer_frame, text='Sign Up', style='Ans.TButton',
                                 command=self.signup_button_click)
        self.ans_sub_button.grid(row=0, column=2, pady=10, padx=150)

    def signup_button_click(self):
        signup_con = connect('AppDatabase.db')
        signup_cur = signup_con.cursor()
        signup_cur.execute("""update LoginData 
                            set Question='{0}', Answer='{1}'
                             where Email='{1}'""".format(self.val.get(),
                                                         self.ans_entry.get(), send_email()))
        signup_con.commit()
        signup_con.close()
        messagebox.showinfo('Successful', 'Successfully Signed Up')
        self.destroy()
        Login_Page.Login()


if __name__ == "__main__":

    sign_up_frame = SignUp()
    sign_up_frame.mainloop()

    def send_email():
        email_id = sign_up_frame.get_email()
        return email_id

    safety_question = SafetyQuestion()
    safety_question.mainloop()

0 个答案:

没有答案