shreddish
shreddish

Reputation: 1764

creating an interactive Python GUI that generates a new list

I'm trying to create a python GUI that takes a list that I've created and populates the list items onto a GUI. This GUI will then give the user the ability to select items in the list and move them over to another list.

So the list item would visually move from one "table" (table1) to the other "table" (table2) in the GUI. Two buttons between the two tables with arrows giving the user the ability to move the items back and forth between the two lists. Finally have a "continue" button that will add all of them items from table2 to a new list when the user is done with his selections.

Is this is something that is possible with TKinter and if so does anyone know of any good tutorials on how to do so? Would other modules be easier for this application?

Upvotes: 1

Views: 5138

Answers (1)

John
John

Reputation: 13699

The widget you'll want to use is called Listbox. Here is a snippet from effbot

from Tkinter import *

master = Tk()

listbox = Listbox(master)
listbox.pack()

listbox.insert(END, "a list entry")

for item in ["one", "two", "three", "four"]:
    listbox.insert(END, item)

mainloop()

Unfortunately I couldn't find any examples of moving two items between two different Listboxes.

After a little bit of playing around I came up with this example that lets you move text between two different Listboxes.

from Tkinter import *

master = Tk()

listbox = Listbox(master)
listbox.pack()

listbox2 = Listbox(master)

def moveDown():

    move_text = listbox.selection_get()
    curindex = int(listbox.curselection()[0])
    listbox.delete(curindex)
    listbox2.insert(END, move_text)

moveBtn = Button(master, text="Move Down", command=moveDown)
moveBtn.pack()


listbox2.pack()

for item in ["one", "two", "three", "four"]:
    listbox.insert(END, item)

mainloop()

Upvotes: 2

Related Questions