[Tutor] Sample Tkinter data entry screen?

Harm Kirchhoff harm.kirchhoff at web.de
Sat Dec 25 13:43:15 CET 2004


Hi Carrol,

What really helped me get going were the Tk inter chapters in
'Programming Python' by Mark Lutz.
Now I am producing Tk inter scripts very often and it is relatively
simple, but it took some time to get used to it.

Hope the following helps:


# Example just for Carrol

from Tkinter import *

class gui:

def __init__(self, root):
"""Implements the graphical surface."""
self.root = root
self.dir = []
# Frame to contain the fields
f = Frame(root) ; f.pack(side=TOP, fill=X)
# Text field for entry:
self.t1 = Text(f, width=20, height=1)
self.t1.pack(side=TOP,expand=YES,fill=X)
self.t2 = Text(f, width=20, height=1)
self.t2.pack(side=TOP,expand=YES,fill=X)

# Button
self.button = Button(root, text = 'Show me input', command = self.show_it )
self.button.pack(side=TOP)
return

def show_it(self):
# get whatever was entered and put it onto the screen
print 't1:',self.t1.get('0.0',END)
print 't2:',self.t2.get('0.0',END)
self.root.destroy()
self.root.quit()

return


if __name__ == '__main__':
# If run as stand alone ...
root = Tk()
gui( root )
mainloop()



-- 
 

 

Kind Regards,

Harm KIRCHHOFF

Private:
Tel. +81-72-297 -2536
Mob. +81-70-5653-8220
Eml: hk at web.de





More information about the Tutor mailing list