Add a new text from Entry into Second Label



  • The situation is:
    I created a few. Label and one Entry♪ But I can't figure out how to add every new text introduced to the new text. Label successively.
    I want to do it. TaskList

    I understand that you need to check if there's one. Label text and if I don't know. Python 3.9

    from tkinter import *
    

    def show_message():
    message2.set(message.get())
    message_entry.delete(0, 'end')
    if # Не могу понять, что писать дальше?

    root = Tk()
    root.title("GUI на Python")
    root.configure(background='#333333')
    root.geometry("600x600")

    MAIN FUNCS

    message = StringVar()
    message2 = StringVar()
    message3 = StringVar()

    message_label = Label(textvariable=message2, anchor="w",
    background='#333333',
    font="Arial 16",
    fg="white")
    message_label.place(width=400, x=110, y=20)

    message_label2 = Label(textvariable=message3, anchor="w",
    background='#333333',
    font="Arial 16",
    fg="white")
    message_label2.place(width=400, x=110, y=50)

    message_entry = Entry(textvariable=message,
    font="Arial 16")
    message_entry.place(width=520, x=10, y=550)

    message_button = Button(text="Add", command=show_message,
    font="Arial 16")
    message_button.place(width=50, height=28, x=540, y=550)



  • Try this:

    import tkinter as tk
    

    class App:
    def init(self):
    self.root = tk.Tk()
    self.root.title("GUI на Python")
    self.root.configure(background='#333333')
    self.root.geometry("600x600")

        self.y = 20
        
        # MAIN FUNCS
        self.message = tk.StringVar()
        self.message_entry = tk.Entry(
            textvariable=self.message,
            font="Arial 16")
        self.message_entry.place(width=520, x=10, y=550)
    
        self.message_button = tk.Button(
            text="Add", 
            command=self.show_message,
            font="Arial 16")
        self.message_button.place(width=50, height=28, x=540, y=550)
    
        self.root.mainloop()
    
    def show_message(self):
        message2 = tk.StringVar()
        message_label = tk.Label(
            textvariable=message2, 
            anchor="w",
            background='#333333',
            font="Arial 16",
            fg="white"
        )
        message_label.place(width=400, x=110, y=self.y)
    
        message2.set(self.message.get())
        self.message_entry.delete(0, 'end')
    
        self.y += 30       
    

    if name == "main":
    app=App()

    введите сюда описание изображения



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2