| | |
Insert text in raw_input
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 11
Reputation:
Solved Threads: 0
Hello,
A complete Python newbie needs help. :-) I have a simple script that updates the 'note' field in a MySQL database table based on the record's id:
The problem with this solution is that the user must enter everything from scratch. What I'd like to do is to allow the user to edit the current contents. For example, if the 'note' field contains the string "Monkey loves banana", the input field would look like this:
Note: Monkey loves banana
and the user can then edit this string. I can easily obtain the contents of the record using the following code:
But how do I add it to the raw_input part?
I hope my question makes sense.
Thank you!
Kind regards,
Dmitri
A complete Python newbie needs help. :-) I have a simple script that updates the 'note' field in a MySQL database table based on the record's id:
Python Syntax (Toggle Plain Text)
id=raw_input("Record id: ") update=raw_input("Note: ") cursor.execute ("UPDATE notes SET note='"+update+"' WHERE id='"+id+"'""") print "\nRecord has been updated."
The problem with this solution is that the user must enter everything from scratch. What I'd like to do is to allow the user to edit the current contents. For example, if the 'note' field contains the string "Monkey loves banana", the input field would look like this:
Note: Monkey loves banana
and the user can then edit this string. I can easily obtain the contents of the record using the following code:
Python Syntax (Toggle Plain Text)
row = cursor.fetchone () contents = row[1]
But how do I add it to the raw_input part?
I hope my question makes sense.
Thank you!
Kind regards,
Dmitri
A simple way to do this would be to write a small GUI code, using the wx.TextEntryDialog widget.
I suggest that you visit this link http://wiki.wxpython.org/AnotherTuto...03278ea4ed8f85
and paste the code section just below, and then drop most of the methods, but the method
I think it's an easy solution since the code is ready to run (you may have to install wxpython
)
I suggest that you visit this link http://wiki.wxpython.org/AnotherTuto...03278ea4ed8f85
and paste the code section just below, and then drop most of the methods, but the method
def textentry . In the text entry, you can edit your record.I think it's an easy solution since the code is ready to run (you may have to install wxpython
) I think your best bet would be to simply print the value of contents and then ask the user for a new value. Otherwise you will need to figure out how to prompt for input and then subsequently write to the stdin ... you can access stdin/stdout via sys.stdxxx, which will allow you to use write, read, etc. Perhaps you can make use of those to create a custom text input function.
![]() |
Similar Threads
- How to inser (anyting I print) to the textbox (TKinter) ?try but it hang? pleas help (Python)
- try to browsing directory using TKinter but give error please help (Python)
- Add text to beggining of document program - problem (Python)
- MySQLdb syntax issues (Python)
- ftplib and the retrbinary() command (Python)
Other Threads in the Python Forum
- Previous Thread: Problem placing Tkinter root window on the screen
- Next Thread: the 'mechanize' library
Views: 1150 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy corners curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o iframe images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive screensaverloopinactive scrolledtext server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython






