In my following program I basicly want to create a edit field which, after I double click it, transforms into a label with the text I wrote in the edit field. Here is my code:
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
And here is my secound file, 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)
Now the problem is, that I get and error and dont know exactly what to do. Following error message I get now:
Exception in Tkinter callback Traceback (most recent call last):
File "C:...\Programs\Python\Python37\lib\tkinter__init__.py", line 1705, in call return self.func(*args) TypeError: done() takes 1 positional argument but 2 were given
Does anybody know what I make wrong and could give me an example how to make it better and improve it?
self.done, the bound method, doesn't take any arguments. The callback is expected to take one. - chepnerself.done()will be called with 2 arguments, the instance reference and the event object, because it is used as callback function ofbind(). - acw1668