memilanuk
December 6th, 2011, 09:18 PM
Hello all,
I'm working on modifying the EasyGUI script from here (http://easygui.sourceforge.net/apps/registration_system/index.html) for my own needs - primarily education and my own amusement ;)
This is what I have so far (using Portable Python 2.7)...
#-------------------------------------------------------------------------------
# Name: easygui-addressbook.py
# Purpose: Simple GUI addressbook
#
# Author: Monte Milanuk
#
# Created: 12/05/2011
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import sqlite3
import pprint
import os
from easygui import *
TITLE = "Address Book"
DATABASE_FILE = "address_book.db"
debugging = "False"
cursor = None # a global
name_id = None # a global
sep = "."
#
# create database & tables
#
def createTables():
global connection
cursor = connection.cursor()
cursor.execute('''CREATE TABLE names (id INTEGER PRIMARY KEY AUTOINCREMENT
, first_name TEXT
, mid_init TEXT
, last_name TEXT
, street_address TEXT
, city TEXT
, state TEXT
, zip TEXT)''')
cursor.execute('''INSERT INTO names(first_name, mid_init, last_name, street_address
, city, state, zip) VALUES("Monte", "E", "Milanuk", "1325 Methow St.", "Wenatchee"
, "WA", "98801")''')
connection.commit()
cursor.close()
msgbox("Database initialized", TITLE)
def main():
pass
#-----------------------------------------------------------------------
# start everything
#-----------------------------------------------------------------------
if __name__ == "__main__":
print TITLE, "starts"
if debugging:
connection = sqlite3.connect(':memory:')
createTables()
else:
if os.path.exists(DATABASE_FILE):
connection = sqlite3.connect(DATABASE_FILE)
else:
connection = sqlite3.connect(DATABASE_FILE)
createTables()
cursor = connection.cursor()
main()
connection.close()
print TITLE, "ends"
Every time I run it, it fires off, prints the line 'Address Book starts.', pops up the message box saying 'Database initialized.' and once I acknowledge that, closes the message box and prints the line 'Address Book ends' and exits. No error messages of any kind, but its apparently not creating the database file as planned, because its not there in the directory afterwards. Every time I run it, it goes thru the createTables function again. I figure it must be something simple, but I'll be danged if I can find it...
TIA,
Monte
I'm working on modifying the EasyGUI script from here (http://easygui.sourceforge.net/apps/registration_system/index.html) for my own needs - primarily education and my own amusement ;)
This is what I have so far (using Portable Python 2.7)...
#-------------------------------------------------------------------------------
# Name: easygui-addressbook.py
# Purpose: Simple GUI addressbook
#
# Author: Monte Milanuk
#
# Created: 12/05/2011
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import sqlite3
import pprint
import os
from easygui import *
TITLE = "Address Book"
DATABASE_FILE = "address_book.db"
debugging = "False"
cursor = None # a global
name_id = None # a global
sep = "."
#
# create database & tables
#
def createTables():
global connection
cursor = connection.cursor()
cursor.execute('''CREATE TABLE names (id INTEGER PRIMARY KEY AUTOINCREMENT
, first_name TEXT
, mid_init TEXT
, last_name TEXT
, street_address TEXT
, city TEXT
, state TEXT
, zip TEXT)''')
cursor.execute('''INSERT INTO names(first_name, mid_init, last_name, street_address
, city, state, zip) VALUES("Monte", "E", "Milanuk", "1325 Methow St.", "Wenatchee"
, "WA", "98801")''')
connection.commit()
cursor.close()
msgbox("Database initialized", TITLE)
def main():
pass
#-----------------------------------------------------------------------
# start everything
#-----------------------------------------------------------------------
if __name__ == "__main__":
print TITLE, "starts"
if debugging:
connection = sqlite3.connect(':memory:')
createTables()
else:
if os.path.exists(DATABASE_FILE):
connection = sqlite3.connect(DATABASE_FILE)
else:
connection = sqlite3.connect(DATABASE_FILE)
createTables()
cursor = connection.cursor()
main()
connection.close()
print TITLE, "ends"
Every time I run it, it fires off, prints the line 'Address Book starts.', pops up the message box saying 'Database initialized.' and once I acknowledge that, closes the message box and prints the line 'Address Book ends' and exits. No error messages of any kind, but its apparently not creating the database file as planned, because its not there in the directory afterwards. Every time I run it, it goes thru the createTables function again. I figure it must be something simple, but I'll be danged if I can find it...
TIA,
Monte