[Tutor] lists and Entry

Mr Gerard Kelly s4027340 at student.uq.edu.au
Wed Jan 14 11:52:21 CET 2009


There is a little Tkinter program. It lets you type something in a box,
and will display it at the command line.


from Tkinter import *

master = Tk()

e = Entry(master)
e.pack()

e.focus_set()

def callback():
  s=e.get()
  print s

b = Button(master, text="get", width=10, command=callback)
b.pack()

mainloop()



The get() method returns a string, how do I make it return a list?
I want to be able to type in 1,2,3 into the box and get [1,2,3] to
appear on the command line.

If I change the callback() method so that it says
s=[e.get()]
I just get a list with one element, the string: ['1,2,3']

If I make it
s=list(e.get())
I get a list with every character as an element: ['1', ',', '2', ',', '3']

How to just get plain [1,2,3]?

many thanks



More information about the Tutor mailing list