Python Widget to read in user input box in blog

James Stroud jstroud at
Tue Apr 24 06:00:21 CEST 2007

ecpbm765 at wrote:
> Hey,
> I am helping to develop a project that displays images based on user
> input.  One possible way of implementing this is via a widget that
> when it is run, would read in the users input from an input text field
> (probably from a blog), and replace it with the HTML that would
> display those images.  This is more a proof of concept, so really all
> I am wondering is if there is a good way in Python to read in the text
> the user has typed and change it before the user hits submit?
> Thanks

You can bind KeyRelease, etc. like such:

#! /usr/bin/env python

from Tkinter import *
from ScrolledText import ScrolledText

def format(t):
   return t.replace('.','!')

def dobind(tin, tout):
   def doit(e=None):
     tout['state'] = NORMAL
     tout.delete('1.0', END)
     newtext = format(tin.get('1.0', END).strip())
     tout.insert(END, newtext)
     tout['state'] = DISABLED
   return doit

def main():
   tk = Tk()
   textin = ScrolledText(tk)
   textin.pack(expand=NO, fill=X)
   textout = ScrolledText(tk)
   textout['state'] = DISABLED
   textout.pack(expand=NO, fill=BOTH)
   textin.bind('<KeyRelease>', dobind(textin, textout))

if __name__ == "__main__":

Etc. includes copy and paste events with mouse.


More information about the Python-list mailing list