#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Win32com apps and Tkinter Listbox


    Hello

    First the Listbox question:

    I have a Listbox with maybe a few 100 items in it now i do curseletion() to find the line but how do I locate what name it is because I need the name to search a file for info.

    Second:

    How I use Word to make a word file and then print it out.
    It will be like a bill and anotherlike a list with all the people.

    thanks for any help...
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Hi monkeyman,

    To answer your Listbox question - use the listbox get() method to read the item stored at an index:

    index_list = lb.curselection()
    value = lb.get(index_list[0])

    Note that index_list is actually a list of indexs of selected items. If you set up your listbox in EXTENDED mode you can select more than one item.

    Here's a quick example of using a Listbox in extended mode:
    Code:
    from Tkinter import *
    
    root = Tk()
    choices = StringVar(root)
    
    # A List box in extended mode allows
    # you to CTRL/SHIFT click items
    lb = Listbox(root, selectmode = EXTENDED)
    
    # Somewhere to display our choice
    Label(root, textvariable = choices).pack()
    
    def getlist(): 
        """Function to read the List Box selection
        and put the results in a Label"""
        sel = lb.curselection()
        seltext = repr([lb.get(x) for x in sel])
        choices.set(seltext)
    
    #Click the button to read the selection
    Button(root, text = "Test", command = getlist).pack()
    
    # Store some items in the Listbox
    items = ["one", "two", "three", "four"]
    for item in items: 
        lb.insert(END, item)
    
    
    lb.pack()
    root.mainloop()
    Have fun

    grim
    Last edited by Grim Archon; April 19th, 2005 at 03:56 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    Thanks

    Do u have any idea about win32com...
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Controlling Word from Python is not a small task If you are really interested - your best bet is to obtain a copy of Mark Hammond's book:
    WIN32 Programming

    It explains the principles but you would still have to do a lot of research to achieve anything useful.

    Happy hacking

    grim
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    Well I would try aleast:P
    But my mom does not wanna buy me another book till my school grades are better
    So thats not possible

IMN logo majestic logo threadwatch logo seochat tools logo