我正在一个项目上,想要将电子邮件的值从一个软件包打包到另一个软件包中,以使用该值更新数据,但是我遇到了这个错误
Exception in Tkinter callback
回溯(最近通话最近一次):
调用中的文件“ C:\ Program Files(x86)\ Python37-32 \ lib \ tkinter__init __。py”,行1705 返回self.func(* args)
文件“ D:/ Boring college / PyProject / MCB2 / sign_up_2.py”,第69行,位于signup_button_click中 sign_up_1.SignUp.send_email())) TypeError:send_email()缺少1个必需的位置参数:“ self”
当我在send_email()中输入self时,它说“期望类型”为“ SignUp”,而不是“ SafetyQuestion” 注册是sign_up_1中存在的类的名称
这是产生错误的代码:
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()
答案 0 :(得分:2)
似乎是一个简单的错误。您实际上并没有将val
变量另存为实例变量。调用val = StringVar()
创建一个onetime变量,在__init__
方法完成运行后您将失去对它的引用。轻松解决:
self.val = StringVar()