I found this code for a label class for a tkinter popup iI was making. I didntdidn't understand how the label appeared, but iI just went on with it. However later iI found that iI needed to refer to the created label in order to bind to it. iI have no idea what line is the actual place the label is being created, so when iI was trying to assign the label to a variable, i didntI didn't know where. canCan someone please explain what is happening in this code and how iI can call back to the label iI just created inside the class?
I figured out the label is being created somewhere where super()super()
is being used and has something to do with the LabelLabel
parameter being passed directly to the class. However after researching what super().init()super().__init__()
did iI figured it just allows classes to use parameters from other classes, so imI'm still confused on how it works when its referring to itself. I also am confused on where the parameters passed directly into the class go (rather that being in the init__init__
)
I
I tried asssigningassigning the super()super()
to a variable, or just using LabelLabel
as a variable, or removing the selfself
. at the beginning.
I made a mini version of the class to see what was going on but to no success. hereHere is the code:
from tkinter import *
class Label(Label):
def __init__(self, root, text, row, col, tag):
self.text = text
self.row = row
self.column = col
self.root = root
self.tag = tag
super().__init__(root)
self['text'] = self.text
self.grid(row=self.row, column=self.column)
# self.label.bind("<Configure>", self.move) # this is the line of code im trying to get to work, but cant because i dont know where the label is being created. it doesnt work
def move(self):
print('moving')
root = Tk()
display = Toplevel()
output = 0
ans = Label(display, output, 0, 0, 'yes')
root.mainloop()
sorrySorry if this is a bad question and or itsit is answered somewhere else this is my first question on here and imI'm pretty sure theres another easy solution but iI just rlyreally want to understand what is happening here.