繁体   English   中英

TypeError:done()接受1个位置参数,但给出了2个

[英]TypeError: done() takes 1 positional argument but 2 were given

在我的以下程序中,我基本上想创建一个编辑字段,双击该字段,将其转换为带有我在编辑字段中编写的文本的标签。 这是我的代码:

GUI.py:

from tkinter import *
import sys
import Classes
root = Tk()
root.wm_title("Schelling-Cup Alpha 1.0")
root.config(background = "#FFFFFF")

#VARIABLEN LADEN

playerlist = []

#BILDER WERDEN GELADEN

hintergrund = PhotoImage(file = "C:\\Users\\Jakub Pietraszko\\Desktop\\MarioKartProject\\Hintergrund2.png")
fotobutton1 = PhotoImage(file = "C:\\Users\\Jakub Pietraszko\\Desktop\\MarioKartProject\\Button_8Spieler_.png")
fotobutton2 = PhotoImage(file = "C:\\Users\\Jakub Pietraszko\\Desktop\\MarioKartProject\\Button_16Spieler_.png")


#FIRSTFRAME EDITED
firstFrame = Frame(root, width=400, height = 400)
firstFrame.grid(row = 0, column = 0, padx = 3, pady = 3)
x = Label(firstFrame, image = hintergrund)
x.grid(row = 0, column = 0)
def callback1():
    """Die Funktion für 8 Spieler, welche dann den entsprechenden Frame lädt."""
    Classes.EditToLabel(400, 400, firstFrame)
    pass
def callback2():
    """Die Funktion für 16 Spieler, welche dann den entsprechenden Frame lädt."""
    pass
B1 = Button(firstFrame, text = "Button1", bg = "#FFFFFF", width = 700, command = callback1)
B1.config(image = fotobutton1)
B1.place(x = 290, y = 250)
B2 = Button(firstFrame, text = "Button2", bg ="#FFFFFF", width = 700, command = callback2)
B2.config(image = fotobutton2)
B2.place(x = 290, y = 450)

#SECOUNDFRAME EDITED

secoundFrame = Frame(root, width = 400, height = 400)


root.mainloop() #GUI wird upgedated. Danach keine Elemente setzen

这是我的第二文件,Classes.py:

from tkinter import *
import sys

x = 100
y = 100

class EditToLabel():
    def __init__(self, x_Koordinate, y_Koordinate, whichFrame):
        self.x_Koordinate = x_Koordinate
        self.y_Koordinate = y_Koordinate
        self.whichFrame = whichFrame

        global neuesEntry
        neuesEntry = Entry(whichFrame, width = 40)
        neuesEntry.place(x = x_Koordinate, y = y_Koordinate)

        neuesEntry.bind('<Double-Button-1>', self.done)
    def done(self):
        Eintrag = neuesEntry.get()
        neuesEntry.destroy()
        neuesLabel = Label(self.whichFrame, text = Eintrag, x = self.x_Koordinate, y = self.y_Koordinate)

现在的问题是,我搞错了,却不知道该怎么做。 我现在收到以下错误消息:

Tkinter回调Traceback中的异常(最近一次调用为last):
文件“ C:... \\ Programs \\ Python \\ Python37 \\ lib \\ tkinter__init __。py”,行1705,在调用返回self.func(* args)TypeError:done()接受1个位置参数,但给出了2个

有人知道我做错了什么,可以举个例子说明如何做得更好和改进吗?

在Tkinter中绑定方法时,即使您不使用它,应用程序也会将有关事件的信息作为参数发送给函数。

尝试:

def done(self, event = None):
    ...

当您需要通过.bind()之外的其他方法使用self.done()时,将“事件”设置为默认参数会self.done()帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM