In Tkinter - having an input and an entry

Fredrik Lundh fredrik at pythonware.com
Sat Apr 5 07:29:27 EDT 2008


markfernandes02 at googlemail.com wrote:

> I can fetch records but cannot insert records.
> 
> def Insert(self, *row):
>     global cursor, title, author, pubdate

using globals to pass arguments to a function/method is usually not a 
good idea.  any reason you cannot pass them in as arguments?

>     sqlInsert = "INSERT INTO Book_table"
>     sqlInsert = sqlInsert + "(Bookname, BookAutor, "
>     sqlInsert = sqlInsert + "Publicationdate) VALUES ('"
>     sqlInsert = sqlInsert + title + "', '"
>     sqlInsert = sqlInsert + author + "', "
>     sqlInsert = sqlInsert + pubdate + ") "
>     myconn = odbc.odbc('accessDatabase')

if you're doing multiple insertions, it's usually better to connect once 
and reuse the connection object.

>     cursor = myconn.cursor()
>     cursor.execute(sqlInsert)
>     myconn.commit()
>     cursor.close()
>     myconn.close()
> 
> The above code does not work.

define "does not work".  do you get a traceback, a database error, some 
other problem?  can you perhaps post the traceback?

> 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.

what did you try?  you can get input data from the Entry widget in 
several ways, including calling the "get" method or using StringVar 
objects; see

    http://effbot.org/tkinterbook/entry.htm#patterns

for some code snippets.

</F>




More information about the Python-list mailing list