Python Tk Tix GUI documentation & builder overview and tips

Discussion in 'Python' started by, Mar 27, 2009.

  1. Guest

    I have recently started development for a small video conversion
    project using a GUI. After some research I decided to use Tkinter/Tix
    (Tk/Tix). The reasons are mainly:

    1. the GUI is rather simple, and

    2. the end-user is not necessarily technically inclined so I want to
    a) required libraries as few as possible, and
    b) installation as painless as possible.

    3. Tk/Tix is included with Python. Thus only a Python installation is
    needed. Nothing else.

    4. Tk itsself misses some rudimentary widgets like meters, multi/colum
    lists, grid and scrolled widgets. Tix provides those. Good enough for
    my little application (more advanced and more modern widgets are
    available in frameworks like Qt, Gtk, or wxWindows).

    Before starting I spent some effort to find
    a) relevant documentation,
    b) GUI Builders which might help me,
    c) answers to non-obvious questions.

    The process took some time and effort so I want to share my findings:

    a) Documentation resources

    Python Docs
    Tk Commands
    Tix Reference
    Tix demo application
    You want to extract the Tix demo application coming with the Tix
    8.4.3 source distribution. It contains examples for many widgets -
    unfortunately none for multi-column HList or the Grid (see below).
    Tix8.4.3-src.tar.gz, then look in /Tix8.4.3/Python/Demo/tix
    Thinking in Tkinter
    I recommend the "Individual programs online"

    b) GUI development tools

    ActiveState GUI Builder (using grid layout)
    SpecTcl is the predecessor of GUI Builder (by ActivaState).
    FAQ (where to get source)

    PAGE v3.0 by Stewart Allen (using placer layout)

    There are many more for other GUI toolkits mentioned in this post:

    Finally I decided to use the packer layout and create the widgets
    manually. Just the simplest and quickest way for me.

    c) How do I ...?

    How do I use all methods available in the Tix Grid?

    Tix Grid with full implementation of all methods

    How do I create a multi-column Tix.HList?

    import Tkinter as Tk
    import Tix

    root = Tix.Tk()
    # setup HList
    hl = Tix.HList(root, columns = 5, header = True)
    hl.header_create(0, text = "File")
    hl.header_create(1, text = "Date")
    hl.header_create(1, text = "Size")
    # create a multi-column row
    hl.add("row1", text = "filename.txt")
    hl.item_create(entry_path, 1, text = "2009-03-26 21:07:03")
    hl.item_create(entry_path, 2, text = "200MiB")

    I haven't found out how to right-justify individual columns? Anyone?

    How to implement Tk GUI with multiple threads?

    Usually there are two options to make threads wait for an event:

    * gui thread polling (lame)
    see here how to use Tk.after() (actually a Tcl command) to poll

    see here how to imitate the Tk event loop to poll for non-Tk
    events (a socket, for example)
    Tix8.4.3-src.tar.gz, then look in /Tix8.4.3/Python/Demo/tix/, find loop()

    * multithreaded with events (the option to choose)
    Basically this uses bind and event_generate to send "Notify"
    messages to the Tk instance.
    I suspect the following example failed due to not synchronising
    the event_generate call

    For multithreading Python Tk GUI applications the following rules
    1. same thread calling Tk must do all subsequent GUI calls,
    2. other threads may send events with send_event to the root Tk
    3. with threading problems you might try to synchonise access to
    event_generate(). Using event_generate() with one non-GUI thread seems
    to be safe.
    , Mar 27, 2009
    1. Advertisements

  2. Aahz

    Aahz Guest

    [posted & e-mailed]

    In article <>,
    <> wrote:
    >Before starting I spent some effort to find
    >a) relevant documentation,
    >b) GUI Builders which might help me,
    >c) answers to non-obvious questions.
    >The process took some time and effort so I want to share my findings:

    Adding this to would be very welcome! (You should
    probably hunt around a bit to find the best spot.)
    Aahz () <*>

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it." --Brian W. Kernighan
    Aahz, Apr 5, 2009
    1. Advertisements

  3. ambri


    Jun 6, 2011
    Likes Received:
    Great work

    I was trying to do the same as you when I found your notes. Good of you to share yours. It helped me a lot.
    ambri, Jun 6, 2011
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.