TypeError:schreiben_methode()缺少1个必需的位置参数:'self'

时间:2016-08-09 14:56:11

标签: python python-3.x oop tkinter

我是Python的新手,现在我有了第一个真正的问题: 我想写一个电子邮件程序,但我不能使用该类发送邮件。我看到了很多这些错误的答案,但没有一个真的对我有用。这是代码:

from tkinter import *

class Versenden(object):
    def testen(self):
        print("Funktioniert")


class Schreiben(object):


    def __init__(self, sender, smtpserver, smtppasswort):
        self.Absender = sender
        self.Smtpserver = smtpserver
        self.Smtppasswort = smtppasswort
        Schreiben.schreiben_methode()

    def schreiben_methode(self):
        root1 = Tk()
        versenden = Versenden()
        labelEmpfaenger = Label(root1, text="Empfaenger:")
        labelBetreff = Label(root1, text="Betreff:")
        empfaenger = Entry(root1)
        betreff = Entry(root1)
        inhalt = Text(root1, height=10, width=50)
        buttonSenden = Button(root1, text="senden", command=lambda: versenden.testen())

        labelEmpfaenger.grid(row=0, column=0)
        empfaenger.grid(row=0, column=1)
        labelBetreff.grid(row=1, column=0)
        betreff.grid(row=1, column=1)
        inhalt.grid(row=2, columnspan=2)
        buttonSenden.grid(row=3, columnspan=2)

        root1.mainloop()

root = Tk()
schreiben = Schreiben("a", "a", "a")

labelEmail = Label(root, text="Ihre Email-Addresse")
labelPasswort = Label(root, text="Ihr Passwort")
labelServer = Label(root, text="SMTP-Server")


email = Entry(root)
passwort = Entry(root)
server = Entry(root)

buttonWeiter = Button(root, text="Weiter", command=lambda: schreiben.schreiben_methode(email, server, passwort))


labelEmail.grid(row=0)
labelPasswort.grid(row=1)
email.grid(row=0, column=1)
passwort.grid(row=1, column=1)
labelServer.grid(row=2)
server.grid(row=2, column=1)
buttonWeiter.grid(row=3, columnspan=2)

root.mainloop()
PS:抱歉我的英语不好,我是德国学生,这就是为什么所有变量和类的名字都是用德语写的,希望这不是问题:)

1 个答案:

答案 0 :(得分:1)

您应该在self上调用该方法,而不是直接从该类调用。

def __init__(self, sender, smtpserver, smtppasswort):
    self.Absender = sender
    self.Smtpserver = smtpserver
    self.Smtppasswort = smtppasswort
    self.schreiben_methode()