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

 
      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
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.


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
  Export data from PDF as tabular format zinho 5 646 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 1,800 Dec-12-2022, 08:22 PM
Last Post: jh67
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,386 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 2,559 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Need Help writing data into Excel format ajitnayak87 8 2,438 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 6,195 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  What is wrong with my format? Oshadha 5 2,441 Jan-14-2021, 12:03 PM
Last Post: Gribouillis
  wrong data reading on uart fahri 6 3,301 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 14,194 Sep-03-2020, 08:22 PM
Last Post: buran
  Issue accessing data from Dictionary/List in the right format LuisSatch 2 2,169 Jul-25-2020, 06:12 AM
Last Post: LuisSatch

Forum Jump:

User Panel Messages

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