Python Widget to read in user input box in blog

E

ecpbm765

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
 
J

James Stroud

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))
tk.mainloop()

if __name__ == "__main__":
main()


Etc. includes copy and paste events with mouse.

James
 
H

half.italian

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

Here's another way. Although I'm not really sure whether you are
talking about a web app or a local gui app.

#! /usr/bin/env python

from Tkinter import *

class Window(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
Label(self, text="Enter the path to a gif").pack(padx=5, pady=5)
self.label = Label(self, text="")
self.label.pack(padx=5, pady=5)
self.entry = Entry(self, text="")
self.entry.pack(padx=5, pady=5)

self.pack()
self.update()

def update(self):
try:
self.image = PhotoImage(file=self.entry.get())
self.label.config(image=self.image)
except TclError:
self.label.config(text=self.entry.get(), image="")
self.after(20, self.update)

if __name__ == '__main__':
root = Tk()
Window().mainloop()

~Sean
 
D

Diez B. Roggisch

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?

Are you talking about a webapplication here? If yes - and the mentioning of
HTML somehow implies that - you can't do that in python, as client-side
code in browsers is Javascript.

However there are frameworks - TurboGears, Django, Pylons - that make rapid
web-application development easy, with good ajax-support.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top