raw_input into Tkinter ?

s0suk3 at gmail.com s0suk3 at gmail.com
Wed Jul 2 03:31:47 CEST 2008


On Jun 30, 11:55 am, jamitwi... at gmail.com wrote:
> Is there any way to type into a Tkinter frame window?
> I want to use raw_input() within a Tkinter frame.

import sys
import Tkinter
import cStringIO

class GUIInputMgr(Tkinter.Entry):

    def __init__(self, parent):
        Tkinter.Entry.__init__(self, parent)

        sys.stdin = cStringIO.StringIO()
        self.bind("<Key>", self.__UpdateBuffer)

    def __UpdateBuffer(self, event):
        sys.stdin.truncate(0)
        sys.stdin.write(self.get())


entry = GUIInputMgr(top) # top is your Tk() instance
entry.pack()

raw_input() # should now get you user input :)

Sebastian



More information about the Python-list mailing list