3 Replies - 2273 Views - Last Post: 31 May 2011 - 01:43 PM Rate Topic: -----

#1 E-Thug  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-May 11

GUI Database Front End Interface userinput

Posted 28 May 2011 - 09:57 PM

So I'm writing a relatively simple app. It's a grocery list app. The user inputs into the GUI which currently is easyGUI but I could use any. It's supposed to take the input from the GUI and then do several things.

1. Save this userinput to a database file. I figured out that I will need to use
file = open('/tmp/agatest', 'r+')

or something similar for this task.

2. Allow the user to sort the entries in this database.

3. Allow the user to run basic statistics or math based operations on the data.

The main problem I'm having is I cannot grok easyGUI, in specific I've figured out how to take the strings and print them to the python console, but I don't have a clue how to capture the strings and integers and store them in the database. And the easyGUI documentation either is not very well written or just doesn't explain itself well.

I'm using multienterbox.

from easygui import *


msgbox(msg="", ok_button="OK")
msgbox("")
msg = ""
title = ""
fieldNames = ["Product Name", "Price ","Product Name","Price","Product Name","Price","Product Name", "Price ","Product Name","Price","Product Name","Price"]
fieldValues = []  # we start with blanks for the values
fieldValues = multenterbox(msg,title, fieldNames)

print fieldValues



This is the basic interface code. It loads a basic interface. A user can enter strings into the interface. It then captures and prints them to the screen. But if I want to capture these strings and integers into an object to be stored into a database, how would I do that?

Is This A Good Question/Topic? 0
  • +

Replies To: GUI Database Front End Interface userinput

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,214
  • Joined: 23-August 08

Re: GUI Database Front End Interface userinput

Posted 29 May 2011 - 04:28 AM

Here's an example:

from easygui import *

# The Product class                                                             
class Product:

    # Product class constructor                                                 
    def __init__(self, name, price):
        self.name = name
        self.price = price

    # Pretty-print the object                                                   
    def __str__(self):
        rv = "Product\n"
        rv += "-------\n"
        rv += "%s $%0.2f\n" % (self.name, self.price)
        return rv

msg = "Enter products"
title = "Product Entry"

# Better than repeating yourself, and it's expandible                           
# Print whatever number of fields you'd like                                    
FIELD_ENTRY_COUNT=6
fields = ("Product Name", "Price")
fieldNames = []
for i in range(FIELD_ENTRY_COUNT):
    for j in range(len(fields)):
        fieldNames.append(fields[j])

fieldValues = []  # we start with blanks for the values                         
fieldValues = multenterbox(msg, title, fieldNames)

# If the user cancels, fieldValues will be None
if fieldValues != None:
    productList = []
    for i in range(len(fieldValues)):

        # Skip empty entries                                                    
        if fieldValues[i] == '' or fieldValues[i+1] == '':
            continue

        # Field names are in the even indexes                                   
        # so if the index is odd, skip it as the value                          
        # is read with the field name                                           
        if i % 2 == 1:
            continue

        # Create a new product and add to our list                              
        try:
            # Make sure the price is sane by treating it                        
            # as a float. The cast to float will cause                          
            # a ValueError if it is non-numeric                                 
            price = float(fieldValues[i+1])

            # All OK, so add to list                                            
            productList.append(Product(fieldValues[i], price))
        except ValueError:
            print "Skipping %s, invalid price entry %s" % (
                fieldValues[i],
                str(fieldValues[i+1]))

    # Print the list                                                           
    for product in productList:
        print product


Was This Post Helpful? 1
  • +
  • -

#3 E-Thug  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-May 11

Re: GUI Database Front End Interface userinput

Posted 31 May 2011 - 02:58 AM

View PostJackOfAllTrades, on 29 May 2011 - 04:28 AM, said:

Here's an example:

from easygui import *

# The Product class                                                             
class Product:

    # Product class constructor                                                 
    def __init__(self, name, price):
        self.name = name
        self.price = price

    # Pretty-print the object                                                   
    def __str__(self):
        rv = "Product\n"
        rv += "-------\n"
        rv += "%s $%0.2f\n" % (self.name, self.price)
        return rv

msg = "Enter products"
title = "Product Entry"

# Better than repeating yourself, and it's expandible                           
# Print whatever number of fields you'd like                                    
FIELD_ENTRY_COUNT=6
fields = ("Product Name", "Price")
fieldNames = []
for i in range(FIELD_ENTRY_COUNT):
    for j in range(len(fields)):
        fieldNames.append(fields[j])

fieldValues = []  # we start with blanks for the values                         
fieldValues = multenterbox(msg, title, fieldNames)

# If the user cancels, fieldValues will be None
if fieldValues != None:
    productList = []
    for i in range(len(fieldValues)):

        # Skip empty entries                                                    
        if fieldValues[i] == '' or fieldValues[i+1] == '':
            continue

        # Field names are in the even indexes                                   
        # so if the index is odd, skip it as the value                          
        # is read with the field name                                           
        if i % 2 == 1:
            continue

        # Create a new product and add to our list                              
        try:
            # Make sure the price is sane by treating it                        
            # as a float. The cast to float will cause                          
            # a ValueError if it is non-numeric                                 
            price = float(fieldValues[i+1])

            # All OK, so add to list                                            
            productList.append(Product(fieldValues[i], price))
        except ValueError:
            print "Skipping %s, invalid price entry %s" % (
                fieldValues[i],
                str(fieldValues[i+1]))

    # Print the list                                                           
    for product in productList:
        print product


if i % 2 == 1:

continue

Produced an index error. So I removed this part and the code works. I'm still facing the same problem, how do I store these values into a database file and then later read it from within the GUI? Is it possible?
Was This Post Helpful? 0
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 756
  • View blog
  • Posts: 1,990
  • Joined: 23-December 08

Re: GUI Database Front End Interface userinput

Posted 31 May 2011 - 01:43 PM

I believe this tutorial will answer your questions :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1