Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17660
| Date | 2011-12-21 08:22 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: Why widgets become 'NoneType'? |
| References | <2073cd5d-a48e-4fa3-8f68-3becbfd8ec97@o7g2000yqk.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3912.1324473733.27778.python-list@python.org> (permalink) |
On 12/21/2011 07:59 AM, Muddy Coder wrote:
> Hi Folks,
>
> I was driven nuts by this thing: widgets lost their attributes, then I
> can't configure them. Please take a look at the codes below:
>
> from Tkinter import *
> canvas = Canvas(width=300, height=400, bg='white')
> canvas.pack(expand=NO, fill=BOTH)
> pic = PhotoImage(file=img)
> canvas.create_image(0, 0, image=pic)
> al = PhotoImage(file='a.gif')
>
> lbl = Label(canvas, text=x, fg='red').pack(side=LEFT)
>
> canvas.create_text(40,20, text='Howdy')
>
> the last line of code got error message, says canvas object has no
> attribute of config. The same problem happened again, the code is
> below:
>
> def make_labels(win, astr):
>
> labels = []
> for i in range(len(astr)):
> lbl = Label(win, text=astr[i]).pack(side=LEFT )
> labels.append(lbl)
> return tuple(labels)
> def config_labels(atuple, func):
> for lbl in atuple:
> lbl.config('%s') % func
>
> root = Tk()
> lbls = make_labels(root, 'foobar')
> config_labels(lbls, "fg='red'")
>
> The config for Label was picked up: No attributes of config. I tried
> to print type(lbls), and found Python interpreter reported as
> 'NoneType'. I also tried to print out dir(lbls), fount there was no
> attributes I familiar with such as config and such. What is wrong with
> them? Both of the codes above WORKED, since I saw my widgets displayed
> them as I wanted, but I just can't configure them as I usually did.
> Can somebody help me out? I never experience such a weird thing.
> Thanks!
>
> Cosmo
When posting error messages, post it exactly and completely; do not
paraphrase.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why widgets become 'NoneType'? Muddy Coder <cosmo_general@yahoo.com> - 2011-12-21 04:59 -0800 Re: Why widgets become 'NoneType'? Dave Angel <d@davea.name> - 2011-12-21 08:22 -0500 Re: Why widgets become 'NoneType'? woooee <woooee@gmail.com> - 2011-12-21 09:45 -0800 Re: Why widgets become 'NoneType'? Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-21 19:43 -0800
csiph-web