Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
  1  # imports
  2  from tkinter import *
  3  import os, sys
  4  #from scipy import stats
  5  
  6  from PIL import ImageTk, Image
  7  
  8  
  9  # Main Screen
 10  master = Tk()
 11  master.title('Welborn Bank')
 12  
 13  # Image working-
 14  img = Image.open('online-banking.png')
 15  img = img.resize((400,300))
 16  img = ImageTk.PhotoImage(img)
 17  
 18  
 19  def finish_reg():
 20      Name = temp_Name.get()
 21      Age = temp_Age.get()
 22      Gender = temp_Gender.get
 23      Password = temp_Password.get()
 24      all_accounts = os.listdir()
 25      if Name == "" or Age == "" or Gender == "" or Password == "":
 26          notif.config(fg="red", text="All fields are required *")
 27          notif.grid(row=7, column=0)
 28          return
 29  
 30      for name_check in all_accounts:
 31          if Name == name_check:
 32              notif.config(fg="red", text="Account already exists")
 33              return
 34          else:
 35              new_file = open(Name, "w")
 36              new_file.write('Name' + '\n')
 37              new_file.write('Password' + '\n')
 38              new_file.write('Age' + '\n')
 39              new_file.write('Gender')
 40              new_file.write('0')
 41              new_file.write('0')
 42              new_file.close()
 43  
 44  
 45  # Function for clearing the
 46  # contents of all entry boxes
 47  
 48  
 49  '''
 50  
 51  # Function to find compound interest
 52  def calculate_ci():
 53      # get a content from entry box
 54      principle = int(principle_field.get())
 55  
 56      rate = float(rate_field.get())
 57  
 58      time = int(time_field.get())
 59  
 60      # Calculates compound interest
 61      CI = principle * (pow((1 + rate / 100), time))
 62  
 63      # insert method inserting the
 64      # value in the text entry box.
 65      compound_field.insert(10, CI)
 66  
 67  
 68  # Driver code
 69  if __name__ == "__main__":
 70      # Create a GUI window
 71      root = Tk()
 72  
 73      # Set the background colour of GUI window
 74      root.configure(background='light green')
 75  
 76      # Set the configuration of GUI window
 77      root.geometry("400x250")
 78  
 79      # set the name of tkinter GUI window
 80      root.title("Compound Interest Calculator")
 81  
 82      # Create a Principle Amount : label
 83      label1 = Label(root, text="Principle Amount(Rs) : ",
 84                     fg='black', bg='red')
 85  
 86      # Create a Rate : label
 87      label2 = Label(root, text="Rate(%) : ",
 88                     fg='black', bg='red')
 89  
 90      # Create a Time : label
 91      label3 = Label(root, text="Time(years) : ",
 92                     fg='black', bg='red')
 93  
 94      # Create a Compound Interest : label
 95      label4 = Label(root, text="Compound Interest : ",
 96                     fg='black', bg='red')
 97  
 98      # grid method is used for placing
 99      # the widgets at respective positions
100      # in table like structure .
101  
102      # padx keyword argument used to set padding along x-axis .
103      # pady keyword argument used to set padding along y-axis .
104      label1.grid(row=1, column=0, padx=10, pady=10)
105      label2.grid(row=2, column=0, padx=10, pady=10)
106      label3.grid(row=3, column=0, padx=10, pady=10)
107      label4.grid(row=5, column=0, padx=10, pady=10)
108  
109      # Create a entry box
110      # for filling or typing the information.
111      principle_field = Entry(root)
112      rate_field = Entry(root)
113      time_field = Entry(root)
114      compound_field = Entry(root)
115  
116      # grid method is used for placing
117      # the widgets at respective positions
118      # in table like structure .
119  
120      # padx keyword argument used to set padding along x-axis .
121      # pady keyword argument used to set padding along y-axis .
122      principle_field.grid(row=1, column=1, padx=10, pady=10)
123      rate_field.grid(row=2, column=1, padx=10, pady=10)
124      time_field.grid(row=3, column=1, padx=10, pady=10)
125      compound_field.grid(row=5, column=1, padx=10, pady=10)
126  
127      # Create a Submit Button and attached
128      # to calculate_ci function
129      button1 = Button(root, text="Submit", bg="red",
130                       fg="black", command=calculate_ci)
131  
132      # Create a Clear Button and attached
133      # to clear_all function
134      button2 = Button(root, text="Clear", bg="red",
135                       fg="black", command=clear_all)
136  
137      button1.grid(row=4, column=1, pady=10)
138      button2.grid(row=6, column=1, pady=10)
139  
140      # Start the GUI
141      root.mainloop()
142  
143  '''
144  
145  
146  def register():
147      global temp_Name
148      global temp_Age
149      global temp_Gender
150      global temp_Password
151      global notif
152  
153      temp_Name = StringVar()
154      temp_Age = StringVar()
155      temp_Gender = StringVar()
156      temp_Password = StringVar()
157  
158      register_screen = Toplevel(master)
159      register_screen.title('Register')
160  
161      Label(register_screen, text="Please Enter your Details to Register", font=('Calibri bold', 31), fg='Purple').grid(row=0, sticky=N,pady=20)
162      Label(register_screen, text="Name", font=('Calibri', 20),fg='Blue').grid(row=1, sticky=W, pady=10)
163      Label(register_screen, text="Age", font=('Calibri', 20),fg='Blue').grid(row=2, sticky=W)
164      Label(register_screen, text="Gender", font=('Calibri', 20),fg='Blue').grid(row=3, sticky=W)
165      Label(register_screen, text="Password", font=('Calibri', 20),fg='Blue').grid(row=4, sticky=W)
166  
167      Entry(register_screen, textvariable=temp_Name, bg='Black', fg='White', font=(12)).grid(row=1, column=0)
168      Entry(register_screen, textvariable=temp_Age, bg='Black', fg='White', font=(12)).grid(row=2, column=0)
169      Entry(register_screen, textvariable=temp_Gender, bg='Black', fg='White', font=(12)).grid(row=3, column=0)
170      Entry(register_screen, textvariable=temp_Password, show="*", bg='Black', fg='White', font=(12)).grid(row=4, column=0)
171  
172      Button(register_screen, text="Register", font=('Calibre Bold' ,15),fg='Red',bg='Yellow',command=finish_reg).grid(row=8, column=0)
173  
174  
175  '''def fixed_deposit(self):
176          print('for fixed deposit: ')
177          d = float(input('enter the duration: '))
178          r = float(input('enter the rate of interest: '))
179          a = float(input('enter the amount: '))
180          si = (a * r * d) / 100
181          print('your amount after', d, 'years is', si, )
182          self.balance = self.balance + si
183          print('final balance is: ', self.balance)
184  
185      def recurring_deposit(self):
186          print('for recurring deposit: ')
187          d = int(input('enter the duration in months: '))
188          r = float(input("enter the rate of interest: "))
189          a = float(input("enter the monthly payment:"))
190          cf = float(input("enter the compound frequency:"))
191          if (d > 6 and d < 120) and (a > 1000):
192              rd = a * (1 + r / cf) * (cf * d)
193              print("The recurring deposit amount after ", d, "months is", rd)
194          else:
195              print("recurring deposit is not permitted")'''
196  
197  
198  def login_session():
199  
200      global login_Name
201      all_accounts = os.listdir()
202      login_Name = temp_login_Name.get()
203      login_password = temp_login_Password.get()
204  
205      for Name in all_accounts:
206          if Name == login_Name:
207              file = open(Name, 'r')
208              file_data = file.read()
209              file_data = file_data.split('\n')
210              password = file_data[1]
211  
212              # account dashboard
213  
214              if login_password == password:
215                  login_screen.destroy()
216                  account_dashboard = Toplevel(master)
217                  account_dashboard.title('Account Dashboard')
218  
219                  # labels
220                  Label(account_dashboard, text="Account Dashboard", font=('Calibri Bold', 32)).grid(row=0, sticky=N, pady=10)
221                  Label(account_dashboard, text="Welcome" + ' ' +  Name, font=('Calibri bold', 22), fg='red').grid(row=1, sticky=N, pady=10)
222  
223                  # Buttons
224                  Button(account_dashboard, text="Personal Details", font=('Calibri', 18), width=25, command= personal_details).grid(row=2, sticky=N, padx=10)
225                  Button(account_dashboard, text="Deposit", font=('Calibri', 18), width=25, command=deposit).grid(row=3, sticky=N,padx=10)
226                  Button(account_dashboard, text="Withdraw", font=('Calibri', 18), width=25, command=withdraw).grid(row=4, sticky=N, padx=10)
227                  Button(account_dashboard, text="Fixed Deposit", font=('Calibri', 18), width=25, command=fixed_deposit).grid(row=5, sticky=N, padx=10)
228  
229                  Label(account_dashboard).grid(row=6, sticky=N, pady=10)
230                  return
231  
232              else:
233                  login_notif.config(fg='Red', text='Password Incorrect')
234                  return
235      login_notif.config(fg='red', text='No account found')
236  
237  
238  def deposit():
239      # vars
240      global amount
241      global deposit_notif
242      global current_balance_label
243      amount = StringVar()
244      file = open(login_Name,'r')
245      file_data = file.read()
246      user_details = file_data.split('\n')
247      details_balance = user_details[4]
248  
249      # deposit screen
250      deposit_screen = Toplevel(master)
251      deposit_screen.title('Deposit')
252  
253      # label
254      Label(deposit_screen, text='Deposit', font=('Calibri bold', 33)).grid(row=0,column=0,sticky=N, pady=10)
255      current_balance_label = Label(deposit_screen, text='current balance:$' + details_balance, font=('Calibri', 23))
256      current_balance_label.grid(row=1, sticky=W)
257      Label(deposit_screen, text='Amount', font=('Calibri', 23)).grid(row=2, sticky=W)
258      deposit_notif = Label(deposit_screen, font=('Calibri', 23))
259      deposit_notif.grid(row=4, sticky=N, pady=5)
260      # entry
261      Entry(deposit_screen, textvariable=amount).grid(row=2, column=1)
262      # button
263      Button(deposit_screen, text='Deposit', font=('Calibri', 15), command=finish_deposit).grid(row=3, sticky=W, pady=5)
264  
265  
266  def finish_deposit():
267      if amount.get() == '':
268          deposit_notif.config(text='amount is required', fg='red', font = ("Cambria italic" ,23))
269          return
270  
271      if float(amount.get()) <= 0:
272          deposit_notif.config(text='Negative Currency is not accepted', fg='red')
273          return
274  
275      file = open(login_Name, 'r+')
276      file_data = file.read()
277      details = file_data.split('\n')
278      current_balance = details[4]
279      updated_balance = current_balance
280      updated_balance = float(updated_balance) + float(amount.get())
281      file_data = file_data.replace(current_balance, str(updated_balance))
282      file.seek(0)
283      file.truncate(0)
284      file.write(file_data)
285      file.close()
286      current_balance_label.config(text='current balance : $ ' + str(updated_balance), fg='green')
287      deposit_notif.config(text='balance updated', fg='green')
288  
289  
290  def withdraw():
291      # Vars
292      global withdraw_amount
293      global withdraw_notif
294      global current_balance_label
295      global amount
296      withdraw_amount = StringVar()
297      amount = IntVar()
298      file = open(login_Name, "r")
299      file_data = file.read()
300      user_details = file_data.split('\n')
301      details_balance = user_details[4]
302      # withdraw Screen
303      withdraw_screen = Toplevel(master)
304      withdraw_screen.title('Withdraw')
305  
306      # Label
307      Label(withdraw_screen, text="Withdraw", font=('Calibri bold', 33)).grid(row=0, column=0,sticky=N, pady=10)
308      current_balance_label = Label(withdraw_screen, text="Current balance:$" + details_balance, font=('Calibri', 23))
309      current_balance_label.grid(row=1, sticky=W)
310      Label(withdraw_screen, text="Amount:", font=('Calibri', 23)).grid(row=2, sticky=W)
311      withdraw_notif = Label(withdraw_screen, font=('Calibri', 23))
312      withdraw_notif.grid(row=4, sticky=N, pady=5)
313      # Entry
314      Entry(withdraw_screen, textvariable='amount').grid(row=2, column=1)
315      # Button
316      Button(withdraw_screen, text="Withdraw", font=('Cambria,', 15), command=finish_withdraw).grid(row=5, sticky=W, pady=5)
317  
318  
319  def finish_withdraw():
320      if withdraw_amount.get == "":
321          withdraw_notif.config(text='Amount is required!', fg="red")
322          return
323      if float(withdraw_amount.get()) <= 0:
324          withdraw_notif.config(text='Negative currency is not accepted', fg='red')
325          return
326      file = open(login_Name, 'r+')
327      file_data = file.read()
328      details = file_data.split('\n')
329      current_balance = details[4]
330  
331      if float(withdraw_amount.get()) > float(current_balance):
332          withdraw_notif.config(text='Insufficient Funds!', fg='red')
333          return
334  
335      updated_balance = current_balance
336      updated_balance = float(updated_balance) - float(withdraw_amount.get())
337      file_data = file_data.replace(current_balance, str(updated_balance))
338      file.seek(0)
339      file.truncate(0)
340      file.write(file_data)
341      file.close()
342  
343      current_balance_label.config(text="Current balance : $" + ' ' + str(updated_balance), fg="green", font=('Cambria',23))
344      withdraw_notif.config(text="Balance Updated", fg="green")
345  
346  
347  def personal_details():
348      # Vars
349      file = open(login_Name, 'r')
350      file_data = file.read()
351      user_details = file_data.split('\n')
352      details_name = user_details[0]
353      details_age = user_details[2]
354      details_gender = user_details[3]
355      details_balance = user_details[4]
356  
357      personal_details_screen = Toplevel(master)
358      personal_details_screen.title('Personal Details')
359  
360      # Labels
361      Label(personal_details_screen, text="Personal Details", font=('Calibri bold', 40)).grid(row=0, column=1,sticky=N, pady=10)
362      Label(personal_details_screen, text="Name : " + details_name, font=('Cambria', 25)).grid(row=1,column=1, sticky=W)
363      Label(personal_details_screen, text="Age : " + details_age, font=('Cambraia', 25)).grid(row=2, column=1,sticky=W)
364      Label(personal_details_screen, text="Gender : " + details_gender, font=('Cambria', 25)).grid(row=3, column=1,sticky=W)
365      Label(personal_details_screen, text="Balance : $ " + details_balance, font=('Cambria', 25)).grid(row=5, column=1, sticky=W)
366  
367  
368  def login():
369      # Vars
370  
371      global temp_login_Name
372      global temp_login_Password
373      global login_notif
374      global login_screen
375      temp_login_Name = StringVar()
376      temp_login_Password = StringVar()
377  
378      # LOGIN SCREEN
379      # print("This is a login page")
380      login_screen = Toplevel(master)
381      login_screen.title('Login')
382  
383      Label(login_screen, text="LOGIN TO YOUR ACCOUNT", font=('Calibri bold', 29), fg='Red',bg='Cyan').grid(row=0, column=0,sticky=N, pady=15)
384      Label(login_screen, text="Username ", font=('Cambria bold', 15)).grid(row=1, sticky=W)
385      Label(login_screen, text="Password  ", font=('Cambria bold', 15)).grid(row=2, sticky=W)
386      login_notif = Label(login_screen, font=('Calibri bold', 25))
387      login_notif.grid(row=5, column=2,sticky=N)
388  
389      # entries
390      Entry(login_screen, textvariable=temp_login_Name, font=(14), fg='White', bg='black').grid(row=1, column=0, padx=3)
391      Entry(login_screen, textvariable =temp_login_Password, show="*", font=(14), fg='white', bg='Black').grid(row=2, column=0, padx=3)
392      # Buttons
393      Button(login_screen, text='LOGIN', command=login_session, width=15, font=('Palatino', 14), fg='blue').grid(row=7,column=0, sticky=W, pady=5, padx=5)
394  
395  
396  '''def fixed_deposit():
397      print('for fixed deposit: ')
398          d=float(input('enter the duration: '))
399          r=float(input('enter the rate of interest: '))
400          a=float(input('enter the amount: '))
401          si=(a*r*d)/100
402          print('your amount after',d, 'years is' ,si,)
403          self.balance=self.balance+si
404          print('final balance is: ', self.balance)'''
405  
406  
407  def fixed_deposit():
408      # vars
409      global fd_amount
410      global fixed_deposit_notif
411      global current_balance_label
412      fd_amount = StringVar
413      file = open(login_Name,'r')
414      file_data = file.read()
415      user_details = file_data.split('\n')
416      details_balance = user_details[4]
417  
418      # deposit screen
419      fixed_deposit_screen = Toplevel(master)
420      fixed_deposit_screen.title('Fixed Deposit')
421  
422      # label
423      Label(fixed_deposit_screen, text='Fixed Deposit', font=('Calibri Bold', 33)).grid(row=0,column=0,sticky=N, pady=10)
424      current_balance_label = Label(fixed_deposit_screen, text='current balance: $' + details_balance, font=('Calibri', 23))
425      current_balance_label.grid(row=1, sticky=W)
426      Label(fixed_deposit_screen, text='Amount', font=('Calibri', 23)).grid(row=2, sticky=W)
427      Label(fixed_deposit_screen, text='Rate of Interest', font=('Calibri', 23)).grid(row=3, sticky=W)
428      Label(fixed_deposit_screen, text='Duration', font=('Calibri', 23)).grid(row=4, sticky=W)
429      Label(fixed_deposit_screen, text= 'Compounding type', font=('calibri',23)).grid(row=5,sticky=W)
430      fixed_deposit_notif = Label(fixed_deposit_screen, font=('Calibri', 23))
431      fixed_deposit_notif.grid(row=6, sticky=N, pady=5)
432  
433      # entry
434      Entry(fixed_deposit_screen, textvariable= 'Amount').grid(row=2, column=1)
435      Entry(fixed_deposit_screen, textvariable= 'Rate Of Interest').grid(row=3, column=1)
436      Entry(fixed_deposit_screen, textvariable= 'Duration').grid(row=4, column=1)
437      Entry(fixed_deposit_screen, textvariable= 'Compounding type').grid(row=5, column=1)
438      # button
439      Button(fixed_deposit_screen, text='Calculate', font=('Calibri', 15), command=finish_deposit).grid(row=6, sticky=W, pady=5)
440  
441  
442  def finish_fixed_deposit():
443      if fd_amount.get() == '':
444          deposit_notif.config(text='All Details are required', fg='red', font = ("Cambria italic" ,23))
445          return
446  
447      if float(fd_amount.get()) <= 0 and (float(amount.get()) < 10000):
448          deposit_notif.config(text='Sorry, Negative Values are not accepted and Amount is less than $10000', fg='red')
449          return
450  
451      file = open(login_Name, 'r+')
452      file_data = file.read()
453      details = file_data.split('\n')
454      current_balance = details[4]
455      updated_balance = current_balance
456  
457      def fd_amount():
458          print(float(input("Enter Amount: ")), fd_amount)
459  
460      def rate_of_interest():
461          print(float(input("Enter Rate of Interest: ")), rate_of_interest)
462  
463      def duration():
464          print(float(input("Enter the tenure: ")), duration)
465  
466      def comp():
467          print(int(input("Enter compounding payout : ")), comp)
468  
469      updated_balance = fd_amount*(1 + rate_of_interest/comp)**(duration*comp)
470  
471      file_data = file_data.replace(current_balance, str(updated_balance))
472      file.seek(0)
473      file.truncate(0)
474      file.write(file_data)
475      file.close()
476      current_balance_label.config(text='current balance : $ ' + str(updated_balance), fg='green')
477      deposit_notif.config(text='balance updated', fg='green')
478  
479  
480  Label(master, text="WELBORN Bank", font=('Calibri Bold', 45)).grid(row=0, sticky=N)
481  Label(master, text="Always at your service", font=('Calibri italic', 19)).grid(row=1, sticky=N, pady=10)
482  Label(master, image=img).grid(row=2, sticky=N, pady=25, padx=25)
483  
484  
485  # Buttons
486  Button(master, text="Register", font=('Calibri', 20),fg='yellow',bg='Blue' ,width=20, command = register).grid(row=3, sticky=N)
487  Button(master, text="Login", font=('Calibri', 20),fg='yellow',bg='Blue', width=20, command = login).grid(row=4, sticky=N, pady=13)
488  
489  
490  master.mainloop()
491  
492  
493  # Points to be added further - RD and Loan calculator


What I have tried:

I have tried changing StringVar to FloatVar or IntVar, but in vain [Omit those in comments]
[I get this error When I try to deposit some money]
Posted
Updated 25-Jan-22 0:46am
v2
Comments
Richard Deeming 25-Jan-22 6:19am    
Dumping 493 lines of unexplained code and an error message, without even telling us which line of code the error relates to, is not a good question.
Achyuth S.S. 25-Jan-22 6:54am    
Line number 280 is the error.... i am sorry that I forgot to put the line of error
Richard MacCutchan 25-Jan-22 6:52am    
The error is telling you that whatever StringVar.get() is returning, is not a valid floating point number. So you need to check exactly what characters are being returned from your text box.

And in future, please post only the code that is relevant to the problem, and provide complete details, including the line of code where the error occurs.
Achyuth S.S. 25-Jan-22 6:56am    
Thank you !!! But we checked those already, and still not getting it, and my question if FloatVar is included in tkinter library, or should I define it afresh?

Richard MacCutchan 25-Jan-22 7:13am    
What have you checked? The problem remains that you are calling float() on a string that is not valid. So you need to fix that before you go any further.

1 solution

Very Clear, some of your lines in code don't have valid float data. Best way to find the error is implement exception handling in your code. Python Exception Handling Using try, except and finally statement[^] Or print some log/message to find where you are getting error.

Secondly, such errors can occur when you are reading data from file/datasource containing space at the start/end. So, make sure there is no space with value or use strip() method while conversion.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900