#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    136
    Rep Power
    10

    Tkinter question


    have googled for a while on this, but didn't find anything so I try ask here:

    In Tk.Entry -- how can I have state=DISABLED and also have uneditable text in it?

    I have this:

    Code:
    self.entry_fra = Entry(frame, state=DISABLED)
    I want to have load some text into it that is uneditable for the user. How do I do it?

    Thanks in advance!
    Dag
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    51
    Hi!

    I would do it like this:
    - create the Entry with state=DISABLED
    - if you want to insert something, set the state to NORMAL
    - insert whatever you want
    - set the state to DISABLED again

    Regards, mawe
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    What mawe says will work but it is not the best way IMO. If you use Tkinter variables you can reduce the amount of work and hassle.

    The sample below shows three widgets, (a label and two entry boxes) one entry widget "e1" uses a Tkinter variable , the other "e2" is updated using the basic Entry methods:
    Code:
    from Tkinter import *
    import time
    
    count = 0
    root = Tk()
    
    myText = StringVar(root) # A Tkinter String Variable
    
    Label(root, textvariable=myText).pack() #Just a label
    
    e1= Entry(root, textvariable=myText, state=DISABLED) #An entry using a Tkinter variable
    e2 = Entry(root, text = '-1', state=DISABLED) #An entry not using a Tkinter variable
    
    def change_it():
        global count
       
        myText.set(count) #updates the Label and e1
        
        ####To change e2 you do this####
        e2.configure(state=NORMAL)
        e2.delete('0',INSERT)
        e2.insert(INSERT,str(count))
        e2.configure(state=DISABLED)
        ################################
    
        try:
            root.update()
        except:
            return
        count = count +1
        root.after(1000,change_it) # Register the function again
    
    e1.pack()
    e2.pack()
    
    
    root.after(1000,change_it()) # Register a function to be called in the future
    root.mainloop()
    To change e1 takes one line of code, e2 needs 4.

    To read the value in e1 you can use the e1.get() method or mytext.get().

    grim

    Comments on this post

    • monkeyman23555 agrees : Yup I Agree
    Last edited by Grim Archon; April 18th, 2005 at 06:11 AM. Reason: added get()
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    136
    Rep Power
    10
    thanks : o)

IMN logo majestic logo threadwatch logo seochat tools logo