How do you do this in python with tk?

Ali alikakakhel3 at hotmail.com
Tue Oct 12 18:02:40 EDT 2004


Eric Brunel <eric_brunel at despammed.com> wrote in message news:<416b8d92$0$7227$8fcfb975 at news.wanadoo.fr>...
> Ali wrote:
> >>Setting state='disabled' does not only prevent the user from editing the text, 
> >>but also prevents *you* from modifying the text via the insert or delete 
> >>methods. So whenever you want to insert or delete lines in the text, you must 
> >>configure its state to 'normal' before, do the modification, then set back its 
> >>state to 'disabled'
> >>
> >>HTH
> > 
> > 
> > OK so I tryed:
> > 
> > import Tkinter
> > def add_rows(w, titles, rows):
> >     t.state = 'normal'
> 
> tk options are not exposed as widget attributes, but via the configure method or 
> dictionary-style indexing. So this should be:
> 
> w.configure(state='normal')
> 
> or:
> 
> w['state'] = 'normal'
> 
> What you did only creates a new attribute named "state" for the widget, which 
> has no meaning at all at tk level.
> 
> [snip]
> 
> HTH

well I tryed this:

import Tkinter
def add_rows(w, titles, rows):
    t.configure(state = 'normal')
    w.configure(state = 'normal')
    for r in rows:
        for t, v in zip(titles, r):
            w.insert("end", "%s:\t%s\n" % (t, v))
        w.insert("end", "\n")

app = Tkinter.Tk()
t = Tkinter.Text(app)
t.pack()
info = [['Ali',18],
        ['Zainab',16],
        ['Khalid',18]]
add_rows(t, ["Name", "Age"], info)
app.mainloop()

Well... it shows the window, it doesnt show text, it still lets me type in stuff :( 
What is wrong now?



More information about the Python-list mailing list