[Tutor] Buttons
moore william
red_necks25 at yahoo.com
Sat Jan 31 21:35:00 EST 2004
I have a cash program that I am trying to create
buttons for instead of a simple number menu. I
understand that I need to import the Tkinter, create
and position the widgets, and enter the main loop
(Python in a nut shell). But I am still having
problems. I have attached the code I have to this
point.
import shelve
s = shelve.open('d:/College/numberdata')
if s.has_key('numbers'):
numbers = s['numbers']
else:
numbers = {}
class AccountTransaction(object):
def __init__(self, amount, time):
self.amount = amount
self.time = time
def __repr__(self):
description = time.ctime(self.time) + ' '
if self.amount < 0:
description += '-'
description += '$' + str(abs(self.amount))
return description
def __init__(self, initial):
self.balance = amount
while 1:
print
print
print 'Show Me The Money'
print '1. Deposite'
print '2. Withdraw'
print '3. Getbalance'
print '9. Quit'
print
choice = int(raw_input('Enter your choice: '))
# I added the exception line so that negartive
numbers woudl not be added.
if choice == 1:
amount = raw_input ('Amount: ')
elif amount < 0:
raise ValueError, 'Deposites must be positive'
elif self.balance - amount < 0:
raise ValueError, 'The account only holds $' +
str(self.balance)
self._perform_transaction(-amount)
date = raw_input ('Date: ')
numbers[amount] = date
# I added the exception line so that only positive
numbers woudl eb entered for withdraws. line so that
elif choice == 2:
amount = raw_input ('Amount: ')
if amount < 0:
raise ValueError, 'Withdrawals must be
negative'
elif self.balance - amount < 0:
raise ValueError, 'The account only holds $' +
str(self.balance)
self._perform_transaction(-amount)
date = raw_input ('Date: ')
numbers[amount] = date
elif choice == 3:
print
for amount, date in numbers.items():
print '%-20s : %-14s' % (amount, date)
elif choice == 9:
break
else:
print_menu()
print "Goodbye"
class Account:
def Deposit(self, amt):
self.balance = self.balance + amt
def Withdraw(self,amt):
self.balance = self.balance - amt
def getbalance(self):
return self.balance
##save numbers when done
s['numbers'] = numbers
s.close()
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
More information about the Tutor
mailing list