Tkinter ListBox and dictionaries
<p>Displaying list items in a tkinter listbox looks like this:</p>

<pre><code>from tkinter import *

root = Tk()

lst = ["one", "two", "three"]
lstbox = Listbox(root)
lstbox.pack()

for item in lst:
    lstbox.insert(END, item)

root.mainloop()
</code></pre>

<p>How can I display a dictionary with both its keys and values using a listbox? </p>

<p>Iterate over the keys of the dictionary and insert a string comprising the key and its value. You can use <code>str.format()</code> to create the string. Here's an example:</p>

<pre><code>d = {"one": 1, "two": 2, "three": 3}

for key in d:
    lstbox.insert(END, '{}: {}'.format(key, d[key]))
</code></pre>

<hr>

<p>Note that the items will not be in any particular order because dictionaries are unordered. You could sort the keys like this:</p>

<pre><code>for key in sorted(d):
    lstbox.insert(END, '{}: {}'.format(key, d[key]))
</code></pre>

python dictionary tkinter listbox