1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] python tkinter append list

Discussão em 'Python' iniciado por Stack, Abril 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am an amateur python programer with 2 months of experience. I am trying to write a GUI to-do list through tkinter. The actual placement of the buttons are not important. I can play around with those after. I need some help with displaying the appended item to the list. In the program, it updates well on the digit, but it won't print onto the list. I double checked it on the console and it says "tkinter.StringVar object at 0x102fa4048" but didn't update the actual list. What I need help is how can I update the list Main_Q on my the label column? Much appreciate some direction and coding help. Thanks.

    Main_Q =["read","clean dishes", "wash car"]


    from tkinter import*
    root=Tk(className="total tasks in the Q")


    #formula

    def update():
    global Main_Q
    a=len(Main_Q)
    num.set(a)

    def add2list():
    Main_Q.append(name)
    a=len(Main_Q)
    num.set(a)
    print (Main_Q)


    #output

    num=StringVar()
    y=Label(root, textvariable=num).grid(row=0, column=1)

    #input

    name=StringVar()
    b=Entry(root, textvariable=name).grid(row=7,column=0)


    #buttons
    z=Button(root, text="update", command=update).grid(row=7, column=2)
    add2list=Button(root,text="add", command=add2list).grid(row=7,
    column=1)


    r = 0
    for c in Main_Q:
    Label(text=c, relief=RIDGE,width=15).grid(row=r,column=0)
    r = r + 1

    root.mainloop()

    Continue reading...

Compartilhe esta Página