[Tkinter-discuss] Newbie needs help with entrybox

Gigs_ gigs at hi.t-com.hr
Wed Jun 6 20:22:36 CEST 2007


Simon Pickles wrote:
> 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
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
> __________ NOD32 2313 (20070606) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
>
>
>   
from Tkinter import *
import tkMessageBox
from time import ctime, time

class CGUI(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.output = Listbox(self, width=100, height=30)
        self.output.pack()
        self.inputBox = Entry(self, bd=5, width=100)
        self.inputBox.pack(side=BOTTOM, expand=YES, fill=BOTH)
        self.inputBox.bind("<Return>", lambda event: 
self.parseInput(self.inputBox.get()))

    def parseInput(self, s):
        self.output.insert(END, s)
        self.inputBox.delete(0, END)

CGUI().mainloop()


here it is
dont use grid and pack in same parent. it will not work.

i explain more but my english is bad and dont know how to express myself


More information about the Tkinter-discuss mailing list