PREET TYAGI
PREET TYAGI

Reputation: 1

Exception in Tkinter callback Traceback (most recent call last):

I'm working on a project and want to use the value of email form one package into another to use the value to update data but I'm getting this error

Exception in Tkinter callback

Traceback (most recent call last):

File "C:\Program Files (x86)\Python37-32\lib\tkinter__init__.py", line 1705, in call return self.func(*args)

File "D:/Boring college/PyProject/MCB2/sign_up_2.py", line 69, in signup_button_click sign_up_1.SignUp.send_email())) TypeError: send_email() missing 1 required positional argument: 'self'

When i enter self in send_email() it says Expected type 'SignUp' got 'SafetyQuestion' instead SignUp is the name of class present in sign_up_1

This is the code that produces the error:

from tkinter import *
from tkinter.ttk import *
from sqlite3 import *
from tkinter import messagebox
import sign_up_1
import Home_page


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)

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

        self.r1 = Radiobutton(self, text='What is your nickname?', variable=val, value='What?')                
        self.r1.pack(anchor=W, pady=10, padx=10)
        self.r2 = Radiobutton(self, text='What is the name of your pet?', variable=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=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=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(),
                                                        sign_up_1.SignUp.send_email()))
        signup_con.commit()
        signup_con.close()
        messagebox.showinfo('Successful', 'Successfully Signed Up')
        self.destroy()
        Home_page.HomePage()


if __name__ == "__main__":
    safety_question = SafetyQuestion()
    safety_question.mainloop()

Upvotes: 0

Views: 31027

Answers (1)

Robert Kearns
Robert Kearns

Reputation: 1706

Appears to be a simple error. You are not actually saving the val variable as an instance variable. Calling val = StringVar() creates a onetime variable, that you lose reference to after the __init__ method finishes running. Easy fix:

self.val = StringVar()

Upvotes: 2

Related Questions