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


Groups > comp.lang.python > #31258 > unrolled thread

Tkinter how to access the widget by name

Started byВладимир Пылев <clinicalfilm@gmail.com>
First post2012-10-14 13:11 -0700
Last post2012-10-16 18:52 -0700
Articles 5 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  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

#31258 — Tkinter how to access the widget by name

FromВладимир Пылев <clinicalfilm@gmail.com>
Date2012-10-14 13:11 -0700
SubjectTkinter how to access the widget by name
Message-ID<40621ce6-1b68-4cfa-8baf-cbfefce4f32b@googlegroups.com>
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 ..!!!!

[toc] | [next] | [standalone]


#31346

From"Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Date2012-10-15 22:26 +0000
Message-ID<mailman.2244.1350339981.27098.python-list@python.org>
In reply to#31258
???????? ????? 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.  

[toc] | [prev] | [next] | [standalone]


#31467

FromВладимир Пылев <clinicalfilm@gmail.com>
Date2012-10-16 22:35 -0700
Message-ID<fcc0cef6-539b-4b00-abf9-163ba8cee489@googlegroups.com>
In reply to#31346
вторник, 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 )).

[toc] | [prev] | [next] | [standalone]


#31468

FromВладимир Пылев <clinicalfilm@gmail.com>
Date2012-10-16 22:35 -0700
Message-ID<mailman.2322.1350452138.27098.python-list@python.org>
In reply to#31346
вторник, 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 )).

[toc] | [prev] | [next] | [standalone]


#31445

Fromwoooee <woooee@gmail.com>
Date2012-10-16 18:52 -0700
Message-ID<a6f06e17-ec7f-4774-bd31-1e72de4a6633@p5g2000pbs.googlegroups.com>
In reply to#31258
On Oct 14, 1:11 pm, Владимир Пылев <clinicalf...@gmail.com> wrote:
> 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 do not understand your question, but I think you want something like

def configure(name):   ## note that a colon is required here
   name.configure(bg='green')
   #  or
   name['bg']='green'

label_1 = Label(frame, width = 40, text='text')
configure(label_1)
label_2 = Label(frame, width = 40, text='label_2')
configure(label_2)

If this is not what you want, post an example that is more specific.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web