There is a task: to make a window with a button, by clicking on which you can create a new tkinter.Label() , and the number is not limited. So, with the window and other things I will figure it out myself, but how can I write such a script so that it generates new tkinter.Label() with unique names (optional)? Please give just a referral to a theory or a piece of code with an explanation (optional), please.

    1 answer 1

    You can try to use the place(x, y) linker and add coordinates depending on the location of the widgets.

     import tkinter class Main(tkinter.Tk): def __init__(self): super().__init__() self.number_y = 50 self.number = 0 tkinter.Label(self, text="Какой то текст {}".format(self.number)).place(x=0, y=self.number_y) tkinter.Button(self, text='Press', command=self.func).place(x=0, y=0, w=100) def func(self): self.number_y += 20 self.number += 1 tkinter.Label(self, text="Какой то текст {}".format(self.number)).place(x=0, y=self.number_y) if __name__ == "__main__": root = Main() root.mainloop() 

    or via pack() add widgets one by one

     import tkinter class Main(tkinter.Tk): def __init__(self): super().__init__() self.number = 0 tkinter.Button(self, text='Press', command=self.func).pack() tkinter.Label(self, text="Какой то текст {}".format(self.number)).pack() def func(self): self.number += 1 tkinter.Label(self, text="Какой то текст {}".format(self.number)).pack() if __name__ == "__main__": root = Main() root.mainloop()