473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Python Widget to read in user input box in blog

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

Apr 24 '07 #1
3 1987
ec******@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
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
Apr 24 '07 #2
On Apr 23, 6:57 pm, ecpbm...@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

Apr 24 '07 #3
ec******@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?
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
Apr 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
59
by: Hugh Macdonald | last post by:
I've recently been trying out various different GUI frameworks in Python and was wondering if I could get your input on the pros and cons of the different ones... wxPython: I love the...
0
by: Cameron Laird | last post by:
QOTW: "I've forgotten what we are arguing about, but I'm sure I'm right." -- Jive Dadson "I believe the best strategy against Identity theft is bad credit." -- Tom Willis "You can't live...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
3
by: Kenneth McDonald | last post by:
If this is not an appropriate newsgroup for this type of posting, please let me know and (if possible) suggest an alternative. I've done a fair bit of research on the net, but information is...
134
by: Joseph Garvin | last post by:
As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
29
by: 63q2o4i02 | last post by:
Hi, I'm interested in using python to start writing a CAD program for electrical design. I just got done reading Steven Rubin's book, I've used "real" EDA tools, and I have an MSEE, so I know what...
4
by: conan | last post by:
This regexp '<widget class=".*" id=".*">' works well with 'grep' for matching lines of the kind <widget class="GtkWindow" id="window1"> on a XML .glade file However that's not true for the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.