[Tutor] Shortening the code

Mic o0MB0o at hotmail.se
Sat Nov 26 13:52:01 CET 2011


>Not really, but a list can handle any kind of data, even functions, 
>objects etc (but they are all types of data too)
>I was just being specific that I meant the list of data used to
>configure your widgets. I should probably just have used its name!

Alright! By the way, it seems like some people favour the use of pastebins, 
while others don’t, which is the way to go and why?


>Really? I get an error:

>Traceback (most recent call last):
  >File "/home/alang/src/Python/chairs.py", line 32, in <module>
    >app = Window(root)
  >File "/home/alang/src/Python/chairs.py", line 14, in __init__
    >self.create_widgets()
  >File "/home/alang/src/Python/chairs.py", line 21, in create_widgets
    >command = partial(button_clicked, button)
>UnboundLocalError: local variable 'button' referenced before assignment

>Which correctly reports that you are using button before it is created.
>There is also a bug in that the color parameter should, of course, 
>be bg...

Strange, I got that error now when I tried to run it just now. But it took like 30 seconds for the error to actually
appear. Do you have any idea why this happened?

>When I change create_widgets() to:

    > def create_widgets(self):
        >list_chair=[(0, 0, '01'), (0, 1, '02'),
                 > (0, 3, '03'), (0, 4, '04'),
                  >(1, 0, '05')]
        >for row, column, name in list_chair:
            >button = tk.Button(self, bg='green',
                               text=name)
            >button['command'] = partial(button_clicked, button)
            >button.grid(row=row, column=column)

>It works as expected


Yes it works perfectly fine now. I wonder, in the last section of the code:
>button.grid(row=row, column=column)

Could I put columnspan in there?
Like:
Button.grid(row=row, column=column, columnspan=columnspan)
That is not necessary to do, I just was curious if that was possible.



Also, I have came to the conlcusion that if I should add the textfiles we discussed 
earlier on, would I somehow put them in the list, list_chair? 
Assuming you feel that it is time for do this, how do I implement the creation of
these text files into the code that we discussed earlier?


Thanks for your help and suggestion!


Mic


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111126/2868dcdf/attachment.html>


More information about the Tutor mailing list