In Tkinter - having an input and an entry
Steve Holden
steve at holdenweb.com
Sat Apr 5 07:07:04 EDT 2008
markfernandes02 at googlemail.com wrote:
> I need some advice,
> I am creating a python program to communicate with an MS Access db in
> python 2.4.
> I can fetch records but cannot insert records.
>
> def Insert(self, *row):
> global cursor, title, author, pubdate
> sqlInsert = "INSERT INTO Book_table"
> sqlInsert = sqlInsert + "(Bookname, BookAutor, "
> sqlInsert = sqlInsert + "Publicationdate) VALUES ('"
> sqlInsert = sqlInsert + title + "', '"
> sqlInsert = sqlInsert + author + "', "
> sqlInsert = sqlInsert + pubdate + ") "
First of all, read about parameterized queries so that you don't do any
more of this. Abbreviated version: formulate your query so that
cursor.execute takes a query with parameter slots in it as the first
argument and a data set as the second argument.
> myconn = odbc.odbc('accessDatabase')
> cursor = myconn.cursor()
> cursor.execute(sqlInsert)
> myconn.commit()
> cursor.close()
> myconn.close()
>
> The above code does not work.
Secondly, observe that in a GUI environment the valuable traceback
information will likely be completely lost, so you should get your code
working first in a command-line based tool that will provide information
about what is going wrong. "Does not work" is way to vague for anyone to
be able to provide helpful responses. We need to see specific tracebacks
(though kudos for actually listing your code: some people effectively
just say the equivalent of "My program to do X does not work, can you
tell me what's wrong with it"!).
> Also with Tkinter, i want to have user input records into the db, i
> cannot get what the user inputs into the entry to become a string
> variable.
>
That's usually a matter of calling the appropriate widget's correct
method. For example, if you have an Entry widget called e you would
retrieve the input from it by calling e.get - see
http://effbot.org/tkinterbook/entry.htm
for documentation from the effbot, the font of all Tkinter knowledge.
> If you can help it would be most appreciated.
> Thanks in advanced
>
Did my best.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list