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


Groups > comp.lang.python > #31346

RE: Tkinter how to access the widget by name

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: Tkinter how to access the widget by name
Date 2012-10-15 22:26 +0000
References <40621ce6-1b68-4cfa-8baf-cbfefce4f32b@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2244.1350339981.27098.python-list@python.org> (permalink)

Show all headers | View raw


???????? ????? 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.  

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