Add/Edit Customer

Add Customer

Above UI we are going to create by Tkinter for adding customer in our Bank management system desktop application. For that first we create a window and configure its title, size and color. Here we are creating a window at Top Level so we can add this window at the top of any other window.

    
        root = tk.Toplevel()

        root.title("Add/Edit Customer")

        root.configure(bg="#585858")
        root.resizable(width=0, height=0)
        win_width = 1280
        print(1280 * 56.25 / 100)
        win_height = int(1280 * 56.25 / 100)
        root.geometry(str(win_width) + "x" + str(win_height))

        # Get screen size
        screen_width = root.winfo_screenwidth()
        screen_height = root.winfo_screenheight()
        Util.set_font_size(screen_width, screen_height, win_width, win_height)

        self.width = win_width * 96 / 100
        self.height = win_height * 94 / 100
    

After creation of window, we will add a canvas background.

    
    bg_canvas = RoundBackgroundFrame(root, self.width, self.height, padding, cornerradius, self.color, "#585858")
    bg_canvas.place(width=self.width, height=self.height, x=win_width / 2 - self.width / 2, y=win_height / 2 - self.height / 2)

    class RoundBackgroundFrame(tk.Canvas):

        def __init__(self, parent, width, height, padding, cornerradius, color, bg):
            tk.Canvas.__init__(self, parent, borderwidth=0, relief="flat", highlightthickness=0, bg=bg)
            self.width = width
            self.height = height
            self.padding = padding
            self.cornerradius = cornerradius
            self.color = color
  
            original = Image.open("images/corner.png")
            resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
            self.image_r_t = ImageTk.PhotoImage(resized)

            original = original.rotate(90, expand=0)
            resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
            self.image_l_t = ImageTk.PhotoImage(resized)

            original = original.rotate(90, expand=0)
            resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
            self.image_l_b = ImageTk.PhotoImage(resized)

            original = original.rotate(90, expand=0)
            resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
            self.image_r_b = ImageTk.PhotoImage(resized)

            self.shape(width, height, padding, cornerradius, color)
            (x0, y0, x1, y1) = self.bbox("all")
            width = (x1 - x0)
            height = (y1 - y0)
            self.configure(width=width, height=height)

        def shape(self, width, height, padding, cornerradius, color):
            self.create_polygon((padding, height - cornerradius - padding, padding, cornerradius + padding,
                                padding + cornerradius, padding, width - padding - cornerradius, padding,
                                width - padding, cornerradius + padding, width - padding,
                                height - cornerradius - padding, width - padding - cornerradius, height - padding,
                                padding + cornerradius, height - padding), fill=color, outline=color)

            self.create_image(width - self.image_r_t.width(), 0, image=self.image_r_t, anchor=NW)
            self.create_image(0, 0, image=self.image_l_t, anchor=NW)
            self.create_image(0, height - self.image_l_b.width(), image=self.image_l_b, anchor=NW)
            self.create_image(width - self.image_r_b.width(), height - self.image_r_b.width(), image=self.image_r_b, anchor=NW)


    

Once your window is created with custom background, we will create a frame with some reduced dimensions.

    
    self.width = self.width * 98 / 100
    self.height = self.height * 96 / 100
    self.base_frame = Frame(root, width=self.width, height=self.height, bg=self.color)
    bg_canvas.create_window(self.width / 100, self.height * 2 / 100, anchor=NW, window=self.base_frame)


    # Add Heading Name
    add_heading_label(self.base_frame, self.color, AppConstant.FONT_SIZE, self.height, self.width)

    def add_heading_label(base_frame, color, font_size, height, width):
        label_heading = Label(base_frame, text="Add/Edit Customer", anchor=CENTER, bg=color,font=("Lucida Grande", font_size + 6))
        label_heading.place(width=width * 90 / 100, height=height * 7 / 100, x=width * 5 / 100, y=height * 0.5 / 100)

    # Add line
    add_line_border(self.base_frame, self.color, self.height, self.width)

    def add_line_border(base_frame, color, height, width):
        line_canvas = Canvas(base_frame, bg=color, borderwidth=0, relief="flat", highlightthickness=0)
        line_canvas.place(width=width - 4, height=5, x=2, y=height * 10 / 100)
        line_canvas.create_line(0, 0, width, 0, fill="#787878")


    button_font = add_action_frame(self.base_frame, self.color, self.height, self.width)

    def add_action_frame(base_frame, color, height, width):
        afw = width * 0.32
        afh = height * 0.87
        button_font = ("Lucida Grande", AppConstant.FONT_SIZE - 6)
        label_frame_action = LabelFrame(base_frame, text="Actions", font=button_font, pady=afw * 2 / 100,
                                   padx=afw * 2 / 100, bg=color)
        label_frame_action.place(width=afw, height=afh, x=0, y=height * 0.12)
        return button_font

    add_search_frame(self.base_frame, button_font, self.color, self.height, self.width)

    def add_search_frame(base_frame, button_font, color, height, width):
        sfw = width * 0.660
        sfh = height * 0.87
        label_frame_search = LabelFrame(base_frame, text="Search", font=button_font, pady=sfw * 2 / 100,
                                    padx=sfw * 2 / 100, bg=color)
        label_frame_search.place(width=sfw, height=sfh, x=width * 0.33, y=height * 0.12)
        
    

So we are done with all frame and background UI. Now we will add all the entry box and submit button in action frame to add customer.

    
    # Add Customer UI

    self.cust_name = CustomEntrySimple(self.base_frame, 300, 60, ("Lucida Grande", AppConstant.FONT_SIZE - 6),self.color,"Customer Name")
    self.cust_name.place(x=50, y=150)

    self.cust_contact = CustomEntrySimple(self.base_frame, 300, 60, ("Lucida Grande", AppConstant.FONT_SIZE - 6),self.color,"Contact No")
    self.cust_contact.place(x=50, y=230)

    self.cust_email = CustomEntrySimple(self.base_frame, 300, 60, ("Lucida Grande", AppConstant.FONT_SIZE - 6),self.color,"Email ID")
    self.cust_email.place(x=50, y=310)

    self.cust_adds = CustomEntrySimple(self.base_frame, 300, 60, ("Lucida Grande", AppConstant.FONT_SIZE - 6),self.color,"Address")
    self.cust_adds.place(x=50, y=390)

    self.show_add_customer_button()
        
    

Here is our class CustomEntrySimple:

    
    class CustomEntrySimple(tk.Canvas):

        def __init__(self, parent, width, height, font, color, text):
        tk.Canvas.__init__(self, parent, borderwidth=0, relief="flat", highlightthickness=0, bg=color)

        self.width = width
        self.height = height
        self.color = color

        self.create_text(6, 5, anchor=W, font=font, text=text, fill="#000000")
        self.create_line(5, height - 8, width - 5, height - 8, fill="#808080")

        frame = Frame(parent,width=width * 95 / 100, height=height * 50 / 100, bg=color)
        self.entry = Entry(frame, bg=color, bd=0, highlightthickness=0, font=font)

        self.entry.place(relwidth=1, relheight=1, x=0, y=0)

        self.create_window(6, height / 2 - (height * 50 / 100) / 2, anchor=NW, window=frame)
        self.update()
        

Create a "Submit" button and show it.

    
    def show_add_customer_button(self):
        self.add_button = RoundedButton(self.base_frame, 250, 130 / 2.56, self.color, "images/button37.png",
                                        "ADD CUSTOMER",
                                        font=("Lucida Grande", AppConstant.FONT_SIZE - 2),
                                        command=self.add_customer_click)
        self.add_button.place(x=75, y=self.height * 0.75)


        self.show_add_custom_button()
    
Here is our class RoundedButton:

    
class RoundedButton(tk.Canvas):

    def __init__(self, parent, width, height, bg, icon_path, text, font, command=None):
        tk.Canvas.__init__(self, parent, borderwidth=0, relief="flat", highlightthickness=0, bg=bg)
        self.command = command
        self.width = width
        self.height = height
        self.text = text
        self.font = font

        original = Image.open(icon_path)
        resized = original.resize((int(width), int(height)), Image.ANTIALIAS)
        self.image = ImageTk.PhotoImage(resized)

        self.shape(width, height)
        (x0, y0, x1, y1) = self.bbox("all")
        width = (x1 - x0)
        height = (y1 - y0)
        self.configure(width=width, height=height)
        self.bind("", self._on_press)
        self.bind("", self._on_release)

    def shape(self, width, height):
        self.create_image(0, 0, image=self.image, anchor=NW)
        self.create_text(width / 2, height / 2, anchor=CENTER, font=self.font, text=self.text, fill="#FFFFFF")

    def shape_press(self, width, height):
        self.create_image(0, 0, image=self.image, anchor=NW)
        self.create_text(width / 2, height / 2, anchor=CENTER, font=self.font, text=self.text, fill="#000000")

    def _on_press(self, event):
        self.configure(relief="sunken")
        self.delete("all")
        # self.update()
        self.shape_press(self.width, self.height)

    def _on_release(self, event):
        self.configure(relief="raised")
        self.delete("all")
        self.shape(self.width, self.height)
        if self.command is not None:
        self.command()
        

Now Create a Search UI for already added customer in bank. First we create a entry box to search Customers with Customer Id and Customer Name.

    
    self.ce_customer_var = CustomEntry(self.base_frame, 300, 55, 10, 2, self.color, "Search Customer","images/ic_search.png")
   
    self.ce_customer_var.place(x=self.width / 2 - 150, y=self.height * 0.20)
   
    self.ce_customer_var.entry.bind('', self.search_customer)
                        

Here is our class CustomEntry:

    
class CustomEntry(tk.Canvas):

    def __init__(self, parent, width, height, cornerradius, padding, color, text, icon_path):
        tk.Canvas.__init__(self, parent, borderwidth=0, relief="flat", highlightthickness=0, bg=color)

        self.width = width
        self.height = height
        self.cornerradius = cornerradius
        self.padding = padding
        self.color = color
        original = Image.open(icon_path)
        resized = original.resize((int(height * 35 / 100), int(height * 35 / 100)), Image.ANTIALIAS)
        self.image = ImageTk.PhotoImage(resized)  # Keep a reference, prevent GC


        self.create_text(6, 7, anchor=W, font=font.Font(family="Lucida Grande", size=12, weight='bold'),text=text, fill="#000000")
        self.create_image(10, height / 2 - self.image.width() / 2, image=self.image, anchor=NW)
        self.create_line(5, height - 8, width - 5, height - 8, fill="#808080")


        frame = Frame(parent,width=width * 86 / 100, height=height * 50 / 100, bg=color)
        self.entry = Entry(frame, bg=color, bd=0, highlightthickness=0,font=font.Font(family="Lucida Grande", size=13, weight='normal'))


        self.entry.place(relwidth=1, relheight=1, x=0, y=0)

        self.create_window(width - width * 86 / 100 - 5, height / 2 - (height * 50 / 100) / 2, anchor=NW, window=frame)
        self.update()


        (x0, y0, x1, y1) = self.bbox("all")
        width = (x1 - x0)
        height = (y1 - y0)
        self.configure(width=width, height=height)
        

Here's the logic to search data in table

    
    def search_customer(self, *arg):


        if self.ce_customer_var.entry.get() != "":
            self.tree.delete(*self.tree.get_children())
            conn = Util.connect_db()
            cursor = conn.cursor()
            status = "Active"
            cursor.execute("SELECT * FROM `customer` WHERE status LIKE ? AND (`customer_name` LIKE ? OR `customer_id` LIKE ?)",
                            (status, '%' + str(self.ce_customer_var.entry.get()) + '%',
                            '%' + str(self.ce_customer_var.entry.get()) + '%'))
            fetch = cursor.fetchall()


            for data in fetch:
                self.tree.insert('', 'end', values=data)

            cursor.close()
            conn.close()


        else:
            self.reset_search()

    def reset_search(self):
        self.tree.delete(*self.tree.get_children())
        self.update_table_data()
                            

We have created a Database named "bankmanagement.db", lets connect that database and put that code in seperate class "Util" because we are going to use it multiple time in our project.

    
    class Util:

        @staticmethod
        def connect_db():
            db = None
            try:
                db = sql.connect("bankmanagement.db")
                return db
            except sql.Error as error:
                print("Failed to insert data into sqlite table", error)
                

Fetch data from database and show it in table form with the use of "Treeview" of Tkinter.

    
    conn = Util.connect_db()
    cursor = conn.cursor()
    status = "Active"

    cursor.execute("SELECT * FROM `customer` WHERE status LIKE ? AND (`customer_name` LIKE ? OR `customer_id` LIKE ?)",(status, '%' + str(self.ce_customer_var.entry.get()) + '%','%' + str(self.ce_customer_var.entry.get()) + '%'))
    fetch = cursor.fetchall()

    style = ttk.Style()
        style.layout("Custom.Treeview.Heading", [
            ("Custom.Treeheading.cell", {'sticky': 'nswe'}),
            ("Custom.Treeheading.border", {'sticky': 'nswe', 'children': [
                ("Custom.Treeheading.padding", {'sticky': 'nswe', 'children': [
                    ("Custom.Treeheading.image", {'side': 'right', 'sticky': ''}),
                    ("Custom.Treeheading.text", {'sticky': 'we'})
                ]})
            ]}),
        ])
       

    style.map("Custom.Treeview.Heading", relief=[('active', 'groove'), ('pressed', 'sunken')])
    style.configure("Custom.Treeview", highlightthickness=0, bd=0, font=('Calibri', 11), rowheight=30)

    self.table_heading()

    self.tree = ttk.Treeview(self.base_frame, height=13, show='tree', style="Custom.Treeview")
    self.tree.tag_configure('odd', background='#DFEBF6', foreground="#000000", )
    self.tree.tag_configure('even', background='#FFFFFF', foreground="#000000", )
    self.tree.place(x=self.width / 2 - 190, y=230)
    self.tree["columns"] = "1", "2", "3", "4", "5", "6"
    self.tree.column("#1", width=110)
    self.tree.column("#0", width=0)
    self.tree.column("#2", width=110)
    self.tree.column("#3", width=110)
    self.tree.column("#4", width=130)
    self.tree.column("#5", width=185)
    self.tree.column("#6", width=110)

    self.update_table_data()

    vsb = ttk.Scrollbar(self.base_frame, orient="vertical", command=self.tree.yview)
    vsb.place(x=self.width - 24, y=230, height=395)

    self.tree.configure(yscrollcommand=vsb.set)
    self.tree.column("#1", anchor=tk.CENTER)
    self.tree.column("#2", anchor=tk.CENTER)
    self.tree.column("#3", anchor=tk.CENTER)
    self.tree.column("#4", anchor=tk.CENTER)
    self.tree.column("#5", anchor=tk.CENTER)

    self.tree.heading("#1", text="Customer Id", anchor=tk.CENTER)
    self.tree.heading("#2", text="Name")
    self.tree.heading("#3", text="Contact No")
    self.tree.heading("#4", text="Email Id")
    self.tree.heading("#5", text="Address")

    self.tree.bind('<>', self.on_tree_click)

    root.attributes('-alpha', 0.0)
    Util.center(root)
    root.attributes('-alpha', 1.0)
        

We have created our own heading for table, lets configure it.

    
    def table_heading(self):

        heading_y = 200

        bg_color = "#046301"
        canvas = Canvas(self.base_frame, width=760, height=30)
        canvas.create_rectangle(0, 0, 760, 30, fill=bg_color)
        canvas.place(x=self.width / 2 - 190, y=heading_y - 3)

        customer_id_label = Label(self.base_frame, text="Customer Id",
                                 font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
                                 foreground="white")
        customer_id_label.place(x=self.width / 2 - 187, y=heading_y, width=130)
        customer_id_label.configure(anchor="center")

        customer_name_label = Label(self.base_frame, text="Name",
                                   font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
                                   foreground="white")
        customer_name_label.place(x=self.width / 2 - 56, y=heading_y, width=100)
        customer_name_label.configure(anchor="center")

        customer_accno_label = Label(self.base_frame, text="Account No",
                                    font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
                                    foreground="white")
        customer_accno_label.place(x=self.width / 2 + 40, y=heading_y, width=125)
        customer_accno_label.configure(anchor="center")

        customer_contact_label = Label(self.base_frame, text="Contact No",
                                      font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
                                      foreground="white")
        customer_contact_label.place(x=self.width / 2 + 175, y=heading_y, width=125)
        customer_contact_label.configure(anchor=W)

        customer_email_label = Label(self.base_frame, text="Email Id",
                                    font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
                                    foreground="white")
        customer_email_label.place(x=self.width / 2 + 315, y=heading_y, width=130)
        customer_email_label.configure(anchor="center")

        customer_adds_label = Label(self.base_frame, text="Address",
                                   font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
                                   foreground="white")
        customer_adds_label.place(x=self.width / 2 + 455, y=heading_y, width=110)
        customer_adds_label.configure(anchor="center")

        

UI part is completed, lets move to funtionality. First we need to add click on "Add Customer" button.

    
    def add_customer_click(self):

        var = ""
        customer_address = ""
        customer_email = ""
        customer_name = ""
        customer_contact = ""
        acc_no = ""
        credit = ""
        debit = ""
        balance = 0
        status = "Active"
        credit_date = ""
        debit_date = ""
        is_address_entered = False
        is_name_entered = False
        is_contact_number_entered = False
        is_email_id_entered = False
        unique_acc = False



        if self.cust_adds.entry.get() == "" or self.cust_adds.entry.get() == " ":
            var += "Address Should not be empty, "
        else:
            customer_address = self.cust_adds.entry.get()
            is_address_entered = True

        if self.cust_email.entry.get() == "" or self.cust_email.entry.get() == " ":
            var += "Email Should not be empty, "
        else:
            customer_email = self.cust_email.entry.get()
            is_email_id_entered = True

        if self.cust_name.entry.get() == "" or self.cust_name.entry.get() == " ":
             var += "Name Should not be empty, "
        else:
            customer_name = self.cust_name.entry.get()
            is_name_entered = True

        if self.cust_contact.entry.get() == "" or self.cust_contact.entry.get() == " ":
            var += "Contact Should not be empty, "
        else:
            customer_contact = self.cust_contact.entry.get()
            is_contact_number_entered = True



        acc_no = get_acc_no()


        trans_id = Util.random_with_N_digits(12)



        if is_name_entered and is_email_id_entered and is_contact_number_entered and is_address_entered:
            conn = Util.connect_db()
            cursor = conn.cursor()

            key = "CUSTOMER_LAST_COUNT"

            cursor.execute('SELECT value FROM system_setting WHERE key IS ?', (key,))
            rows = cursor.fetchone()
  

            id_count = Util.convert_string_to_int(rows[0]) + 1

            customer_id = get_customer_id(id_count) + str(id_count)

            cursor.execute('INSERT INTO customer(customer_id, customer_name, contact_number, email_address, address,'' account_number, status) VALUES(?,?,?,?,?,?,?)',
                          (customer_id, customer_name, customer_contact, customer_email, customer_address, acc_no, status))

            conn.commit()

            cursor.execute('INSERT INTO statement(transaction_id, account_number, credit, debit, balance, credit_date, debit_date) VALUES(?,?,?,?,?,?,?)',
                          (trans_id, acc_no, credit, debit, balance, credit_date, debit_date))

            conn.commit()

            messagebox.showinfo("Success", "Customer has been added successfully")

            self.cust_adds.entry.delete(0, 'end')
            self.cust_email.entry.delete(0, 'end')
            self.cust_contact.entry.delete(0, 'end')
            self.cust_name.entry.delete(0, 'end')

            self.cust_name.entry.focus()

            cursor.execute("UPDATE system_setting SET value = ? WHERE key = ?",(id_count, key,))
            conn.commit()

            cursor.execute('SELECT * FROM customer where status = ?', ("Active",))
            self.sql_output = cursor.fetchall()
            self.tree.delete(*self.tree.get_children())
            for data in self.sql_output:
              self.tree.insert('', 'end', values=data)

        else:
            print(var)
            messagebox.showerror("showerror", var)

            

When we click on "Add Button", data will be added to database, after that we need to update the data on UI.

    
    def update_table_data(self):
        conn = Util.connect_db()
        cursor = conn.cursor()
        status = "Active"
        cursor.execute('SELECT customer_id, customer_name, account_number, contact_number, email_address, address FROM customer where status = ?', (status,))
        self.sql_output = cursor.fetchall()

        for data in self.sql_output:
            self.tree.insert('', 'end', values=data)
    

To edit and delete customer on click on table row, we need to show Edit And Delete Button.

    
    def on_tree_click(self, *args):
        self.show_edit_button()
        self.show_delete_button()


    def show_edit_button(self, *args):
        self.edit_button = RoundedButton(self.base_frame, 110, 130 / 3.75, self.color, "images/button37.png",
                                         "EDIT",
                                         font=("Lucida Grande", AppConstant.FONT_SIZE - 4),
                                         command=lambda: self.edit_customer(self.height, self.color))
        self.edit_button.place(x=self.width / 2 + 240, y=self.height * 0.20)


    def show_delete_button(self, *args):
        self.delete_button = RoundedButton(self.base_frame, 110, 130 / 3.75, self.color, "images/button3.png",
                                           "DELETE",
                                           font=("Lucida Grande", AppConstant.FONT_SIZE - 4),
                                           command=self.delete_customer)
        self.delete_button.place(x=self.width / 2 + 420, y=self.height * 0.20)
    

To edit and customer on Button.

    

    #Edit Customer
    def edit_customer(self, height, color):

        cur_item = self.tree.focus()

        self.cust_name.entry.delete(0, END)
        self.cust_contact.entry.delete(0, END)
        self.cust_email.entry.delete(0, END)
        self.cust_adds.entry.delete(0, END)

        self.cust_name.entry.insert(0, self.tree.item(cur_item)["values"][1])
        self.cust_contact.entry.insert(0, self.tree.item(cur_item)["values"][3])
        self.cust_email.entry.insert(0, self.tree.item(cur_item)["values"][4])
        self.cust_adds.entry.insert(0, self.tree.item(cur_item)["values"][5])

        self.add_button.place_forget()

        customer_id = self.tree.item(cur_item)["values"][0]

        self.hide_edit_button()

        self.update_button = RoundedButton(self.base_frame, 170, 130 / 2.56, color, "images/button37.png", "UPDATE",
                                            font=("Lucida Grande", AppConstant.FONT_SIZE - 2),
                                            command=lambda: self.update_customer_click(customer_id))
        self.update_button.place(x=15, y=height * 0.75)

        self.cancel_button = RoundedButton(self.base_frame, 170, 130 / 2.56, color, "images/button37.png", "CANCEL",
                                            font=("Lucida Grande", AppConstant.FONT_SIZE - 2),
                                            command=self.cancel_button_click)
        self.cancel_button.place(x=205, y=height * 0.75)


    #Delete Customer
    def delete_customer(self):

        cur_item = self.tree.focus()
        customer_id = self.tree.item(cur_item)["values"][0]
        customer_name = self.tree.item(cur_item)["values"][1]
        status = "Inactive"

        response = messagebox.askokcancel("Are you sure?", "Do you want to delete " + customer_name + " ?")
        if response:
            conn = Util.connect_db()
            cursor = conn.cursor()

        cursor.execute("UPDATE customer SET status = ? WHERE customer_id = ?",(status, customer_id,))
        conn.commit()

        self.tree.delete(*self.tree.get_children())
        self.update_table_data()
    

Implement Update And Cancel Button functionality

    
    #Update Customer
    def update_customer_click(self, customer_id):
        var = ""
        customer_email = ""
        customer_name = ""
        customer_contact = ""
        customer_adds = ""
        is_name_entered = False
        is_contact_number_entered = False
        is_email_id_entered = False
        is_adds_entered = False

        if self.cust_email.entry.get() == "" or self.cust_email.entry.get() == " ":
            var += "Email Should not be empty, "
        else:
            customer_email = self.cust_email.entry.get()
            is_email_id_entered = True

        if self.cust_name.entry.get() == "" or self.cust_name.entry.get() == " ":
            var += "Name Should not be empty, "
        else:
            customer_name = self.cust_name.entry.get()
            is_name_entered = True

        if self.cust_contact.entry.get() == "" or self.cust_contact.entry.get() == " ":
            var += "Contact Should not be empty, "
        else:
            customer_contact = self.cust_contact.entry.get()
            is_contact_number_entered = True

        if self.cust_adds.entry.get() == "" or self.cust_adds.entry.get() == " ":
            var += "Address Should not be empty, "
        else:
            customer_adds = self.cust_adds.entry.get()
            is_adds_entered = True

        if is_name_entered and is_email_id_entered and is_contact_number_entered and is_adds_entered:
            conn = Util.connect_db()
            cursor = conn.cursor()
            cursor.execute(
                "UPDATE customer SET customer_name = ?, contact_number = ?, email_address = ?, address = ? WHERE customer_id = ?",
                (customer_name, customer_contact, customer_email, customer_adds, customer_id,))
            conn.commit()

            self.cust_email.entry.delete(0, 'end')
            self.cust_contact.entry.delete(0, 'end')
            self.cust_name.entry.delete(0, 'end')
            self.cust_adds.entry.delete(0, 'end')

            messagebox.showinfo("Success", "Customer detail has been updated successfully")

            self.tree.delete(*self.tree.get_children())
            self.update_table_data()

            self.add_button = RoundedButton(self.base_frame, 250, 130 / 2.56, self.color, "images/button37.png",
                                            "ADD Customer",
                                            font=("Lucida Grande", AppConstant.FONT_SIZE - 2),
                                            command=self.add_customer_click)
            self.add_button.place(x=75, y=self.height * 0.70)

            self.hide_edit_button()
            self.cancel_button.place_forget()
            self.update_button.place_forget()

    #Cancle Button
    def cancel_button_click(self):

        self.cust_email.entry.delete(0, 'end')
        self.cust_contact.entry.delete(0, 'end')
        self.cust_name.entry.delete(0, 'end')
        self.cust_adds.entry.delete(0, 'end')

        self.show_add_customer_button()

        self.show_edit_button()
        self.cancel_button.place_forget()
        self.update_button.place_forget()

    

At last we will manage closing of window

    
    def on_closing():
                        
        root.destroy()
        args[0].deiconify()
                       
    root.protocol("WM_DELETE_WINDOW", on_closing)
                       

Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 2021 by Programmer Mitra. All Rights Reserved.