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)
..Listbox.pack(side=TOP)
...for item in ["lots","of","data","in","here","that","takes","up","four","lines"]:
....Listbox.insert(Tk.END,item)

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?

2 Comments on "Bonus Pathetic Python Sunday"


  1. 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”
    Listbox.insert(Tk.END.item)

    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?

    Reply

  2. This is your problem:
    Listbox.insert(Tk.END,item)

    It should be this:
    self.selector.insert(Tk.END,item)

    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…

    Reply

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.