当前位置: 首页 > 知识库问答 >
问题:

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

凌宏大
2023-03-14
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
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回调跟踪中的异常(最近的调用是最后一次):
文件“C:...\programs\python\python37\lib\tkinter__init__.py”,第1705行,在调用返回self.func(*args)typeError:done()接受1个位置参数,但给出了2个

有谁知道我犯了什么错误,能给我一个例子,如何使它更好和改进吗?

共有1个答案

公羊宇定
2023-03-14

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

尝试:

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

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

 类似资料: