Python TypeError:done()接受1个位置参数,但给出了2个
在我下面的程序中,我基本上希望创建一个编辑字段,双击它后,它将转换为一个标签,其中包含我在编辑字段中编写的文本。这是我的密码: GUI.py:Python TypeError:done()接受1个位置参数,但给出了2个,python,oop,tkinter,Python,Oop,Tkinter,在我下面的程序中,我基本上希望创建一个编辑字段,双击它后,它将转换为一个标签,其中包含我在编辑字段中编写的文本。这是我的密码: 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 = [] #BILD
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
这是我的secound文件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导入*
导入系统
x=100
y=100
类EditToLabel():
定义初始(self,x坐标,y坐标,whichFrame):
self.x_坐标=x_坐标
self.y_Koordinate=y_Koordinate
self.whichFrame=whichFrame
全球中性中心
NeueCentry=入口(框架宽度=40)
新中心位置(x=x坐标,y=y坐标)
neuecentry.bind(“”,self.done)
def完成(自我):
Eintrag=neueCentry.get()
neuecentry.destroy()
neuesLabel=Label(self.whichFrame,text=Eintrag,x=self.x_坐标,y=self.y_坐标)
现在的问题是,我犯了错误,不知道该怎么办。我现在收到以下错误消息:
Tkinter回调回溯中出现异常(最近一次调用最后一次):文件“C:…\Programs\Python\Python37\lib\tkinter\uuuu init\uuuuu.py”,第行 1705,在呼叫中 return self.func(*args)TypeError:done()接受1个位置参数,但给出了2个
有人知道我做错了什么,能给我举个例子说明如何改进吗?在Tkinter中绑定一个方法时,即使你不使用它,应用程序也会将有关事件和参数的信息发送给函数 尝试: 当您需要使用
self.done()
通过除
.bind()
self.done
之外的其他方法,绑定方法不接受任何参数。回调应该接受一个参数。它需要接受参数吗?我的意思是我没有任何东西可以交给曼托德。“回调”是什么意思?将使用实例引用和事件对象这两个参数调用完全相同的self.done()
,因为它被用作bind()
的回调函数。这非常有效,对于解释也非常有用。我真的很喜欢它!
def done(self, event = None):
...