Python Forum
Saves the data in the wrong format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saves the data in the wrong format
#1
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

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
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
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()
Reply
#2
Try remove self.insert() in last line of "insert" function and in "clear" function added tk.END to clear the whole textfield.


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\testuser\Downloads\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\testuser\Downloads\out.png')
        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 = len(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, tk.END)
        self.ePASS.delete(0, tk.END)
  
    def insert(self) :
        current_row = sheet.max_row
        if (len(self.eUSER.get()) == 0 and
            len(self.ePASS.get()) == 0 ):
           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\testuser\Downloads\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\testuser\Downloads\out.png')
  
    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\testuser\Downloads\out.png')
app.master.geometry("500x300")
app.master.title("North American Midway Entertainment")
app.mainloop()
Best Regards,
Sandeep.

GANGA SANDEEP KUMAR
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] [datetime.strptime] ValueError: time data 'foo' does not match format 'bar' Winfried 1 1,445 Jan-02-2025, 02:09 AM
Last Post: lyly19
  Export data from PDF as tabular format zinho 5 2,598 Nov-11-2023, 08:23 AM
Last Post: Pedroski55
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 4,035 Dec-12-2022, 08:22 PM
Last Post: jh67
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 5,288 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 5,244 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Need Help writing data into Excel format ajitnayak87 8 4,198 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 8,910 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  What is wrong with my format? Oshadha 5 3,489 Jan-14-2021, 12:03 PM
Last Post: Gribouillis
  wrong data reading on uart fahri 6 5,013 Sep-29-2020, 03:07 PM
Last Post: Larz60+
  ValueError: time data 'None' does not match format '%Y-%m-%dT%H:%M:%S.%f' rajesh3383 4 22,250 Sep-03-2020, 08:22 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020