I'm quite a noob to this also, but I can say that two things are missing: A
function that your return event would call telling Python what to do when
the event occurs, and mainloop.
For instance, here is a sample code that when you click on it, will tell you
where the mouse click event occurred:
# File: bind1.py
from Tkinter import *
root = Tk()
def callback(event): #this will be called later, the definition of the
event.
print "clicked at", event.x, event.y
frame = Frame(root, width=100, height=100)
frame.bind("<Button-1>", callback) #callback is the function, previously
defined.
frame.pack()
root.mainloop()
HTH
Teresa
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Simon Pickles
Sent: Wednesday, June 06, 2007 9:19 AM
To: [email protected]
Subject: [Tkinter-discuss] Newbie needs help with entrybox
Hello, I am new to python and tkinter, but enjoying it so far.
In trying to make a simple GUI I have stumbled on a problem binding an event
to a function. I've got a listbox for output and an entrybox for input. How
do I act on the text in the entry box when return is pressed?
Here's my attempt:
# GUI
from Tkinter import*
import tkMessageBox
from time import ctime, time
class CGUI:
def __init__(self, master):
frame = Frame(master, name="server")
frame.pack()
self.output = Listbox(frame, width=100, height=30)
self.output.grid(row=0, column=0)
self.inputBox = Entry(root, bd=5, width=100)
self.inputBox.bind( "<KeyPress-Return>",
self.__ParseInput(self.inputBox.get()) )
self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH)
def __ParseInput(self, s):
self.output.insert(END, s)
root = Tk()
gui = CGUI(root)
-------------------------------------------------------------------------
Your advice appreciated!
Thanks
Simon
http://www.simonpickles.com --- http://www.squirtualreality.com
_________________________________________________________________
The next generation of Hotmail is here! http://www.newhotmail.co.uk/
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss
_______________________________________________
Tkinter-discuss mailing list
[email protected]
http://mail.python.org/mailman/listinfo/tkinter-discuss