Sunday, April 01, 2007

Bonus Pathetic Python Sunday

OK, so we solved the last problem. But now I've got another. We've just created a window with a Tkinter frame within, and announced that a listbox will be there. Then, we have the following statement:

self.selector = Listbox(frame)
...for item in ["lots","of","data","in","here","that","takes","up","four","lines"]:

Dots inserted to get the indenting right. Tk.END causes the interpreter to fart a syntax error and then another for every subsequent line. Every imaginable variation (with and without Tk or TK or tk, End, END, end, you get the picture) does this, or else shunts the problem into the data.

Do I have do something weird to make the snake treat the list, which makes up four lines, as a list?


Anonymous said...

First of all, I don't understand your indenting. The only indented line should be the last one. But I assume that's a presentation issue.

Your next problem is the comma between END and item: I think it should be a dot. But that's probably a typo.

Break it down. Try

item = "lots"

Though I think the problem is in the insert line, but I'm not big on Tk stuff.
Where does this data come from? If it takes up lines, does it come from a file?

bonecrusher said...

This is your problem:

It should be this:

You want to insert END into a particular instance of the Listbox ("self.selector"), not into the Listbox class.

PS - if this is a duplicate post, please delete it. The new comments suck too...

kostenloser Counter