[Tkinter-discuss] Entry Labels - .get()

Lion Kimbro lionkimbro at gmail.com
Fri Feb 1 00:39:51 CET 2013

  I'm not really following your code;
  For example, I see "self" referenced, but I have no idea where the class

  But basically, it looks to me like you are creating several IntVar
  but have pointed to them all with only a single self.entVar.

  You might want to instead use something like:

  def __init__(self, all_names):
      self.intvars = {name: tkinter.IntVar() for name in all_names}

  Then, to get the values, you could do something like:

  def vals(self):
      return {name: self.intvars[name].get() for name in self.intvars}

  I think that should work.

On Thu, Jan 31, 2013 at 3:12 PM, Blackpanda <darragh_odowd at yahoo.com> wrote:

> Hi,
> I'm relatively new to Python and am building a GUI using Tkinter. As part
> of
> the GUI I have a form ("frm2") which has a number of enrty labels
> ("self.ent"). These are placed in the form using a double loop (see below).
> I also have a button which I want to return all the entries. The button is
> linked (i.e. using command=self.GetValues) to a function which uses
> self.entVar.get() to try and get all the entries but this only gives me the
> last entry. Any suggestions how I can get all the entries when the button
> is
> pressed?
> frm2 = LabelFrame(cnv, text="Portfolio Weights:", font=("Calibri", 12),
> width=150)
>         #Frame contents
>         for i in range(0, len(Assets_Text)):
>             labi = Label(frm2, width=30, text=Assets_Text[i], anchor='w')
>             labi.grid(row=i+5, column=0, sticky='we')
>             for j in range(0, self.entry2Variable.get()):
>                 lab2 = Label(frm2, text="Portfolio %d" % (j+1), width=10,
>                              font=("Calibri", 10))
>                 lab2.grid(row=4, column=j+1)
>                 self.entVar = IntVar()
>                 self.ent = Entry(frm2, width=10, textvariable=self.entVar)
>                 self.ent.grid(row=i+5, column=j+1)
>                 self.entVar.set(0.00)
> --
> View this message in context:
> http://python.6.n6.nabble.com/Entry-Labels-get-tp5004179.html
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20130131/7e48f1ba/attachment.html>

More information about the Tkinter-discuss mailing list