Help with buttons and entry fields

Steve Holden sholden at holdenweb.com
Tue Sep 5 14:13:01 EDT 2000


Assuming you are still using Tkinter, the code below should elucidate.
The button's callback uses the special insert position END to append
something tpo the entry's current value.

HTH

regards
 Steve


Dudek7 wrote:
> 
> Heres a newbie question.  I have a button and an entry field. Does anyone
> know how to get the entry field to display the number "1" whenever i press
> the button?
> Like if i press button 5 times there are 5 ones?
> 
> Please help me.
> 
> thanks

from Tkinter import *

class createStuff:

    def __init__(self, window=None):
        self.button = Button(window, text="Click Me", command=self.addaone)
        self.entry = Entry(window)
        self.button.pack()
        self.entry.pack()

    def addaone(self):
        self.entry.insert(END, "1")

def close(self):
    self.quit()

if __name__ == "__main__":
    root = Tk()
    win = createStuff(root)
    root.mainloop()

-- 
Helping people meet their information needs with training and technology.
703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/



More information about the Python-list mailing list