[Tutor] Need help

niraj pandey nirajkumarpandey at gmail.com
Wed Sep 28 05:22:07 EDT 2016


Thanks Peter for the help.

Best Regards
Niraj



On Wed, Sep 28, 2016 at 2:47 PM, Peter Otten <__peter__ at web.de> wrote:

> niraj pandey wrote:
>
> > Found the solution for this.
>
> You can further simplifiy it with enumerate()
> > entry_option = ['Flat_No','Mains Unit','DG Unit','Month']
>
> > entry = {}
> > label = {}
>   for r, item in enumerate(entry_option):
> >     lb = Label(bg = 'orange', text=item, relief=RIDGE,width=30)
> >     lb.grid(row=r,column=0)
> >     label[item] = lb
> >     e = Entry(relief=SUNKEN,width=30)
> >     e.grid(row=r,column=1)
> >     entry[item] = e
> >
> > But now how to pass these values as an argument for this function  ?
> >
> > command=lambda: database.data(E1.get(), E2.get(), E3.get(), E4.get())
>
> Well, you saved the Entry instances in a dict, so you can retrieve them:
>
> command=lambda: database.data(*[entry[k].get() for k in entry_option])
>
> If you use a list instead of or in addition to the dict
>
> entries = []
> for ...: # your loop from above
>    ...
>    entries.append(e)
>
> the lambda becomes
>
> command=lambda: database.data(*[e.get() for e in entries])
>
> If you have not come across it before: the * operator unpacks the list, so
>
> args = ["a", "b"]
> f(*args)
>
> is equivalent to calling f with all items in the list,
>
> f(args[0], args[1])
>
> in the above example.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Success occurs when opportunity and preparation meet


More information about the Tutor mailing list