Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31467

Re: Tkinter how to access the widget by name

Newsgroups comp.lang.python
Date 2012-10-16 22:35 -0700
References <40621ce6-1b68-4cfa-8baf-cbfefce4f32b@googlegroups.com> <mailman.2244.1350339981.27098.python-list@python.org>
Message-ID <fcc0cef6-539b-4b00-abf9-163ba8cee489@googlegroups.com> (permalink)
Subject Re: Tkinter how to access the widget by name
From Владимир Пылев <clinicalfilm@gmail.com>

Show all headers | View raw


вторник, 16 октября 2012 г., 2:26:22 UTC+4 пользователь Prasad, Ramit написал:
> ???????? ????? wrote:
> 
> > I'm a little teapot ... himself the question: if I want to appeal to the widget, knowing his name... ?
> 
> > 
> 
> > # appropriated the name of the widget
> 
> > label = Label(frame, width = 40, text='text', name = 'name')
> 
> > ...
> 
> > name_='name'
> 
> > configure(name_)
> 
> > ...
> 
> > def configure(name_)
> 
> >         #And how can that be?
> 
> >         # At least let the text you want to change ....
> 
> > 
> 
> > I beg you ..!!!!
> 
> > --
> 
> 
> 
> I am unfamiliar with Tkinter, so this might not be very helpful.
> 
> 
> 
> Usually with the GUI I have created before I uses classes and store 
> 
> the widgets inside the classes. That makes it easier to use
> 
> `self.widgetname` or `getattr(self, widgetname)`. If that is not
> 
> something you can instead store the attributes in a list/dictionary.
> 
> In both cases make sure not to have multiple widgets created with
> 
> the same name.
> 
> 
> 
> Note the following is all untested and should be considered pseudo-code.
> 
> 
> 
> widgets = {}
> 
> label = Label(frame, width = 40, text='text', name = 'name')
> 
> widgets['name'] = label
> 
> 
> 
> def configure(name_):
> 
>     widget = widgets[name_] 
> 
> 
> 
> OR
> 
> 
> 
> widgets = []
> 
> label = Label(frame, width = 40, text='text', name = 'name')
> 
> widgets.append( label )
> 
> 
> 
> def configure(name_):
> 
>     found = False
> 
>     for w in widgets:
> 
>          if w.name == name_: # No idea how to get name from Tk widget
> 
>                found = True
> 
>                break
> 
>      if found:
> 
>         # configure here
> 
> 
> 
> 
> 
> Ramit Prasad
> 
> 
> 
> 
> 
> This email is confidential and subject to important disclaimers and
> 
> conditions including on offers for the purchase or sale of
> 
> securities, accuracy and completeness of information, viruses,
> 
> confidentiality, legal privilege, and legal entity disclaimers,
> 
> available at http://www.jpmorgan.com/pages/disclosures/email.


ok thanks, that this method is suitable in full: "widgets.append( label )" , аlthough at the beginning wanted to access the widget by its internal name, but I left this venture )).

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Tkinter how to access the widget by name Владимир Пылев <clinicalfilm@gmail.com> - 2012-10-14 13:11 -0700
  RE: Tkinter how to access the widget by name "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-15 22:26 +0000
    Re: Tkinter how to access the widget by name Владимир Пылев <clinicalfilm@gmail.com> - 2012-10-16 22:35 -0700
    Re: Tkinter how to access the widget by name Владимир Пылев <clinicalfilm@gmail.com> - 2012-10-16 22:35 -0700
  Re: Tkinter how to access the widget by name woooee <woooee@gmail.com> - 2012-10-16 18:52 -0700

csiph-web