raw_input into Tkinter ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jamitwidme@gmail.com

    raw_input into Tkinter ?

    Is there any way to type into a Tkinter frame window?
    I want to use raw_input() within a Tkinter frame.
  • Sebastian \lunar\ Wiesner

    #2
    Re: raw_input into Tkinter ?

    jamitwidme@gmai l.com <jamitwidme@gma il.com>:
    Is there any way to type into a Tkinter frame window?
    Maybe using a proper text/line edit widget?
    I want to use raw_input() within a Tkinter frame.
    The builtin raw_input is for console input only. Of course, one could
    implement a raw_input using a Tkinter dialog to query input, but its way
    more easier and comfortable to just write a real GUI application.

    --
    Freedom is always the freedom of dissenters.
    (Rosa Luxemburg)

    Comment

    • Matimus

      #3
      Re: raw_input into Tkinter ?

      On Jun 30, 9:55 am, jamitwi...@gmai l.com wrote:
      Is there any way to type into a Tkinter frame window?
      I want to use raw_input() within a Tkinter frame.
      `raw_input(prom pt)` just calls `sys.stdout.wri te(prompt)` and returns
      `sys.stdin.read line()`. So, you can just create file-like objects to
      replace stdout and stdin that are aware of your Tkinter gui.
      Alternatively, you could just replace __builtins__.ra w_input with your
      own version.

      Actual implementation left as an exercise for the user.

      Matt


      Comment

      • Python.Arno

        #4
        Re: raw_input into Tkinter ?


        On 30 jun 2008, at 18:55, jamitwidme@gmai l.com wrote:
        Is there any way to type into a Tkinter frame window?
        I want to use raw_input() within a Tkinter frame.
        --

        >
        >
        You could use the Tkinter.Entry option from dialog windows...



        gr
        Arno

        Comment

        • Sebastian \lunar\ Wiesner

          #5
          Re: raw_input into Tkinter ?

          Matimus <mccredie@gmail .com>:
          On Jun 30, 9:55 am, jamitwi...@gmai l.com wrote:
          >Is there any way to type into a Tkinter frame window?
          >I want to use raw_input() within a Tkinter frame.
          >
          `raw_input(prom pt)` just calls `sys.stdout.wri te(prompt)` and returns
          `sys.stdin.read line()`.
          It does more like providing readline support, if readline is loaded.



          --
          Freedom is always the freedom of dissenters.
          (Rosa Luxemburg)

          Comment

          • s0suk3@gmail.com

            #6
            Re: raw_input into Tkinter ?

            On Jun 30, 11:55 am, jamitwi...@gmai l.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(Tki nter.Entry):

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

            sys.stdin = cStringIO.Strin gIO()
            self.bind("<Key >", self.__UpdateBu ffer)

            def __UpdateBuffer( self, event):
            sys.stdin.trunc ate(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

            Comment

            Working...