I am having an issue with my data being entered gets saved wrong into my excel file.
i believe the issue relates to my insert function
this is my result
User Name Password
Marvin Marvinpassword
arvin arvinpassword
rvin rvinpassword
vin vinpassword
in inpassword
n npassword
password
assword
ssword
sword
word
ord
rd
d
i cant seem to find the issue.Please help
Here is the full code
i believe the issue relates to my insert function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
def insert( self ) : current_row = sheet.max_row if ( self .eUSER.get() = = "" and self .ePASS.get() = = "" ): print ( "empty input" ) return else : self .eUSER.focus_set() sheet.cell(row = current_row + 1 , column = 1 ).value = self .eUSER.get() sheet.cell(row = current_row + 1 , column = 2 ).value = self .ePASS.get() self .eUSER.bind( "<Return>" , self .focusU) self .ePASS.bind( "<Return>" , self .focusP) self .eUSER.grid(row = 1 , column = 1 , ipadx = "100" ) self .ePASS.grid(row = 2 , column = 1 , ipadx = "100" ) sheet.column_dimensions[ 'A' ].width = 40 sheet.column_dimensions[ 'B' ].width = 40 sheet.column_dimensions[ 'C' ].width = 40 sheet.cell(row = 1 , column = 1 ).value = "User Name" sheet.cell(row = 1 , column = 2 ).value = "Password" sheet.cell(row = 1 , column = 3 ).value = "Security question" wb.save(r 'C:\Users\Hennie\Desktop\new\sheet.xlsx' ) self .clear() self .eUSER.focus_set() self .insert() return |
User Name Password
Marvin Marvinpassword
arvin arvinpassword
rvin rvinpassword
vin vinpassword
in inpassword
n npassword
password
assword
ssword
sword
word
ord
rd
d
i cant seem to find the issue.Please help
Here is the full code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
import tkinter as tk from openpyxl import * wb = load_workbook(r 'C:\Users\Hennie\Desktop\new\sheet.xlsx' ) sheet = wb.active # create new user class BuildApplication(tk.Frame): # Registration window def __init__( self , master = None ): tk.Frame.__init__( self , master) self .current_row = sheet.max_row master.iconbitmap(r 'C:\Users\Hennie\Desktop\new\logo.ico' ) self .grid() self .createWidgets() def createWidgets( self ): self .lUSER = tk.Label( self , text = "Username: " ) self .lUSER.grid(row = 1 ,column = 2 ) self .eUSER = tk.Entry( self ) self .eUSER.grid(row = 2 ,column = 2 ) self .lPASS = tk.Label( self , text = "Password: " ) self .lPASS.grid(row = 3 ,column = 2 ) self .ePASS = tk.Entry( self , show = "*" ) self .ePASS.grid(row = 4 ,column = 2 ) self .LOGIN = tk.Button( self , text = "Create new user" , fg = "black" , command = lambda :[ self .setCredentials(), self .insert()]) self .LOGIN.grid(row = 5 ,column = 2 ) self .QUIT = tk.Button( self , text = "QUIT" , fg = "black" , command = self .master.destroy) self .QUIT.grid(row = 6 ,column = 2 ) def setCredentials( self ): username = self .eUSER.get() password = self .ePASS.get() print ( "username" , username) print ( "password" , password) def focusU( self ) : self .eUSER.focus_set() def focusP( self ) : self .ePASS.focus_set() def clear( self ) : self .eUSER.delete( 0 , ) self .ePASS.delete( 0 , ) def insert( self ) : current_row = sheet.max_row if ( self .eUSER.get() = = "" and self .ePASS.get() = = "" ): print ( "empty input" ) return else : self .eUSER.focus_set() sheet.cell(row = current_row + 1 , column = 1 ).value = self .eUSER.get() sheet.cell(row = current_row + 1 , column = 2 ).value = self .ePASS.get() self .eUSER.bind( "<Return>" , self .focusU) self .ePASS.bind( "<Return>" , self .focusP) self .eUSER.grid(row = 1 , column = 1 , ipadx = "100" ) self .ePASS.grid(row = 2 , column = 1 , ipadx = "100" ) sheet.column_dimensions[ 'A' ].width = 40 sheet.column_dimensions[ 'B' ].width = 40 sheet.column_dimensions[ 'C' ].width = 40 sheet.cell(row = 1 , column = 1 ).value = "User Name" sheet.cell(row = 1 , column = 2 ).value = "Password" sheet.cell(row = 1 , column = 3 ).value = "Security question" wb.save(r 'C:\Users\Hennie\Desktop\new\sheet.xlsx' ) self .clear() self .eUSER.focus_set() self .insert() return # Login Main window class SearchApplication(tk.Frame): ######################### # Login button ######################## def __init__( self , master = None ): tk.Frame.__init__( self , master) self .grid() self .createWidgets() master.iconbitmap(r 'C:\Users\Hennie\Desktop\new\logo.ico' ) def createWidgets( self ): self .some_abel = tk.Label( self , text = " Eventually be the main page when you log in" ) self .some_abel.grid(row = 1 ,column = 1 ) self .quitb = tk.Button( self , text = "quit" , fg = "green" , command = self .master.destroy ) self .quitb.grid(row = 2 ,column = 1 ) # Main window layout class MainApplication(tk.Frame): def __init__( self , master = None ): tk.Frame.__init__( self , master) self .SaveUser = () self .grid() self .createWidgets() def createWidgets( self ): #Save Data self .bBuild = tk.Button( self , text = "Create new user" , command = self .build) self .bBuild.grid(row = 1 ,column = 5 ) #login self .blogin = tk.Button( self , text = "Login" , command = self .login) self .blogin[ "text" ] = "Login" self .blogin[ "command" ] = self .login self .blogin.grid(row = 2 , column = 1 ) #quit self .QUIT = tk.Button( self , text = "QUIT" , fg = "red" , command = self .master.destroy) self .QUIT.grid(row = 3 ,column = 1 ) def build( self ): root2 = tk.Toplevel() buildApp = BuildApplication(master = root2) def login( self ): root3 = tk.Toplevel() app2 = SearchApplication(master = root3) root = tk.Tk() app = MainApplication(master = root) app.configure(background = 'snow1' ) root.iconbitmap(r 'C:\Users\Hennie\Desktop\new\logo.ico' ) app.master.geometry( "500x300" ) app.master.title( "North American Midway Entertainment" ) app.mainloop() |