Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8214503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:29:06+00:00 2026-06-07T11:29:06+00:00

For some reason in the listbox there seems to be brackets around a string

  • 0

For some reason in the listbox there seems to be brackets around a string that ends with a space.

from Tkinter import *

def update_listbox():   
    for i in dic:
        listbox.insert(END, (i, dic[i][0], dic[i][1], dic[i][2]))

dic = {}
dic['Foods'] = ['apple','grape','pizza']
dic['Drinks      '] = ['milk','soda','jucie'] # How do i make the {} not show up but keep the spaces?

root=Tk()
listbox = Listbox(root)
button = Button(root,text='push',command=update_listbox)
button.pack()
listbox.pack()


root.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:29:08+00:00Added an answer on June 7, 2026 at 11:29 am

    I think it’s got something to do with you inserting a tuple element into the listbox rather than one or more strings. Try this instead:

    listbox.insert(END, ' '.join([i]+dic[i])
    

    which concatenates the key and all the sub-elements together into a single string — which also keeps them all on one line — and inserts that single thing into the listbox. Here’s what it looks like on my system after pushing the button:

    listbox with no brackets inserted

    The other alternative would be to unpack the tuple in the call:

    listbox.insert(END, *(i, dic[i][0], dic[i][1], dic[i][2]))
    

    or, better yet, not put them in a tuple in the first place:

    listbox.insert(END, i, dic[i][0], dic[i][1], dic[i][2])
    

    But even better than that, because it would be able to handle lists of any length (as pointed out by @mgilson in the comments) would be to write it this way:

    listbox.insert(END, i, *dic[i])
    

    Regardless, the result would look like this:

    another listbox with no brackets inserted each word on a separate line

    Here’s a way to do things so the listbox will automatically update its width after it’s updated. It also shows another way to build the dictionary and later iterate through its contents when populating the listbox:

    from Tkinter import *
    
    def update_listbox():
        longest = 20  # initial value acts as minimum width
        for key,value in dic.iteritems():
            entry = '{}: {}'.format(key, (', '.join(value)))
            longest = max(longest, len(entry))
            listbox.insert(END, entry)
        listbox.config(width=longest)  # width in "standard" or average characters
    
    dic = {
        'Foods': ['apple','grape','pizza'],
        'Drinks': ['milk','soda','juice'],
    }
    
    root=Tk()
    root.title('Listbox')
    listbox = Listbox(root)
    button = Button(root, text='push', command=update_listbox)
    button.pack()
    listbox.pack()
    
    root.mainloop()
    

    With this result:

    listbox final version

    BTW, here’s a good online Tkinter reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove some objects from a ListBox that I have created, and
For some reason, I was under the impression that it was just called Timeout,
For some reason I have always assumed that most of the time a variable
For some reason I have to initialize the ListBox items in behind code, the
i have the following piece of code, that for some reason that i'm unaware
For some reason, the user that installs this, when they click the button, nothing
For some reason I'm really struggling with this. I'm new to wpf and I
For some reason it looks like constructor delegation doesn't work in the following snippet:
For some reason on my application when running on some configuration of hard disk
For some reason I am not able to use the TextFlow element in WPF.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.