Tkinter and printf in C ...

Steve Holden sholden at holdenweb.com
Sun Jul 8 16:08:08 EDT 2001


"Chyr-Pyng Su" <cpsu at larc.ee.nthu.edu.tw> wrote in message
news:3B48076E.B16ACF5B at larc.ee.nthu.edu.tw...
> Steve Holden wrote:
>
> >
> > Sorry, should have read the subject line. Here's a snippet of code that
> > write to a PMW scrolled text window, you should be able to do the same
in a
> > Tkinter text window.
> >
> >         t = Pmw.ScrolledText(self.msgWindow)
> >         grid(t, row=0, column=0, sticky=N+E+W+S)
> >         strmes =
> > self.index.Message(self.MsgSet[int(self.msgList.curselection()[0])][0])
> >         message = mimecntl.MIME_document(strmes)
> >         for hdr in ("from", "date", "subject", "to", "cc"):
> >             try:
> >                 hdrline = message[hdr]
> >                 t.insert(END, "%s:     %s\n" %
> > (string.capitalize(hdr),hdrline))
> >             except KeyError:
> >                 pass
> >
> > It's the insert() method you are looking for, I suspect.
> >
> > regards
> >  Steve
>
> Thanks in advance to help me writing the GUI program.. Actually I intended
to
> contruct a
> buttom so that when I press it, it will trigger a wrapped function
originally
> written in C.
> And capture those dumped message, show them in ScrolledText() widget..
>
> Sorry, I can't figure out what the self.index is... besides, where should
I
> place these codes..
> in the callback function or in top level... :O
>
OK, I was running a little too fast. The "self" in the code I showed you
referred to the object whose class implementation I had extracted the code
from, so you all you need to know is that is was the parent of the
Pmw.ScrolledText object in which I was rendering text.

Suppose that the error message returned by the wrapped C function has been
stored in st. To create a Text widget in a separate top-level window and
display the message in it, you would do (something like: warning, untested):

        msgWindow = Toplevel(height=350, width=500)
        msgWindow.columnconfigure(0, weight=1)
        msgWindow.rowconfigure(0, weight=1)
        t = Text(msgWindow)
        grid(t, row=0, column=0, sticky=N+E+W+S)
        t.insert(END, st)

I have here assumed that like most Tkinter programmers you have used "from
Tkinter import *", and that you are using (or are prepared to use) the grid
geometry management.

Does this make it any clearer?

regards
 Steve
--
http://www.holdenweb.com/






More information about the Python-list mailing list