I'm trying to create a simple accounting system based off of an example GUI. The coding is as follows:
#!/usr/bin/python from Tkinter import * from os import urandom from twisted.internet import tksupport from twisted.internet import reactor from accounts import accountlist def whichSelected () : print "At %s of %d" % (select.curselection(), len(accountlist)) return int(select.curselection()[0]) def addEntry () : accountlist.append ([userVar.get(), passwVar.get(), balanceVar.get()]) setSelect () def Withdrawl() : user, passw, balance = accountlist[whichSelected()] userVar.set(user) passwVar.set(passw) balanceVar.set(balance) balanceVar -= amount balance.set(balanceVar) setSelect () def Deposit() : user, passw, balance = accountlist[whichSelected()] balance += amount accountlist[whichSelected()] = [user, passw, balance] setSelect () def loadEntry () : user, passw, balance = accountlist[whichSelected()] userVar.set(user) passwVar.set(passw) balanceVar.set(balance) def makeWindow () : global userVar, passwVar, balanceVar, amount, select win = Tk() frame1 = Frame(win) frame1.pack() Label(frame1, text="User Name").grid(row=0, column=0, sticky=W) userVar = StringVar() user = Entry(frame1, textvariable=userVar) user.grid(row=0, column=1, sticky=W) Label(frame1, text="Password").grid(row=1, column=0, sticky=W) passwVar= StringVar() passw= Entry(frame1, textvariable=passwVar) passw.grid(row=1, column=1, sticky=W) Label(frame1, text="Balance ($)").grid(row=2, column=0, sticky=W) balanceVar= IntVar() balance= Entry(frame1, textvariable=balanceVar) balance.grid(row=2, column=1, sticky=W) frame2 = Frame(win) frame2.pack() b1 = Button(frame2,text=" Add ",command=addEntry) b2 = Button(frame2,text="Withdraw Amount",command=Withdrawl) b3 = Button(frame2,text="Deposit Amount",command=Deposit) b4 = Button(frame2,text=" Load ",command=loadEntry) b1.pack(side=LEFT); b2.pack(side=LEFT) b3.pack(side=LEFT); b4.pack(side=LEFT) frame3 = Frame(win) frame3.pack() scroll = Scrollbar(frame3, orient=VERTICAL) select = Listbox(frame3, yscrollcommand=scroll.set, height=6) scroll.config (command=select.yview) scroll.pack(side=RIGHT, fill=Y) select.pack(side=LEFT, fill=BOTH, expand=1) frame4 = Frame(win) frame4.pack() Label(frame4, text="Amount ($)").grid(row=0, column=0, sticky=W) amountVar= IntVar() amount= Entry(frame4, textvariable=amountVar) amount.grid(row=0, column=1, sticky=W) return win def setSelect () : accountlist.sort() select.delete(0,END) for user,passw,balance in accountlist : select.insert (END, user) # Install the Reactor support def main(): root = makeWindow() setSelect () tksupport.install(root) # root.pack() print "starting event loop" reactor.run() #if __name__ == "__main__": main() Also, for reference, the "accounts" imported from are as follows: accountlist = [ ['Alex', 'shera', '400'], ['Sam', 'tish', '0'] ] Thus far, everything works fine unless I'm trying the Deposit or Withdrawal functions. (I know they're different, but both give roughly the same error.) Whenever I attempt one of these functions I get the following error message: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__ return self.func(*args) File "C:\Python24\AEOpaypal.py", line 27, in Deposit user, passw, balance = accountlist[whichSelected()] File "C:\Python24\AEOpaypal.py", line 11, in whichSelected return int(select.curselection()[0]) IndexError: tuple index out of range I honestly don't understand what's going on... I've managed to stumble my way through understanding what error messages mean, but I'm not sure what do here. Just to clarify, to deposit money, first you select the account, and click "Load" to bring it up on screen. Then you put the amount in the "Amount" text box. Then you click "Deposit Amount" Thanks in advance!
-- http://mail.python.org/mailman/listinfo/python-list