Python Widget to read in user input box in blog

half.italian at gmail.com half.italian at gmail.com
Tue Apr 24 07:57:09 CEST 2007


On Apr 23, 6:57 pm, ecpbm... at gmail.com 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

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




More information about the Python-list mailing list