btnReset = Button(f1,
                  bd=20,
                  fg="white",
                  font=('arial', 16, 'bold'),
                  width=10,
                  text="Reset",
                  bg="gray",
                  command=Reset,
                  padx=10,
                  pady=10).grid(row=10, column=1)
#btnPrint=Button(f1,bd=20,fg="black",bg="light green",font=('arial',16,'bold'),width=10,text="Print",command=printing,padx=10,pady=10).grid(row=2,column=1)

#right side(f2)
mlb = MultiListbox(f2, (('Name', 20), ('Quantity', 20), ('Price', 20),
                        ('Amount', 20)))
mlb.grid(row=5, column=1)
lblTotal = Label(f2,
                 font=('arial', 16, 'bold'),
                 bd=10,
                 anchor="w",
                 fg="dark green",
                 textvariable=tot).grid(row=7, column=1)
lblCgst = Label(f2,
                font=('arial', 16, 'bold'),
                textvariable=cgst,
                bd=10,
                anchor="w",
                fg="dark green").grid(row=8, column=1)
lblSgst = Label(f2,
                font=('arial', 16, 'bold'),
                textvariable=sgst,
Beispiel #2
0
class Window(object):
    def __init__(self, window):
        self.window = window
        self.window.wm_title("The Buyers Stop")

        l1 = Label(window, text="Product")
        l1.grid(row=0, column=0)

        l2 = Label(window, text="Seller")
        l2.grid(row=1, column=0)

        l3 = Label(window, text="Price")
        l3.grid(row=2, column=0)

        l4 = Label(window, text="Qty")
        l4.grid(row=3, column=0)

        l5 = Label(window, text="Your total")
        l5.grid(row=15, column=0)

        self.product_text = StringVar()
        self.e1 = Entry(window, textvariable=self.product_text)
        self.e1.grid(row=0, column=1)

        self.seller_text = StringVar()
        self.e2 = Entry(window, textvariable=self.seller_text)
        self.e2.grid(row=1, column=1)

        self.price_text = StringVar()
        self.e3 = Entry(window, textvariable=self.price_text)
        self.e3.grid(row=2, column=1)

        self.qty_text = StringVar()
        self.e4 = Entry(window, textvariable=self.qty_text)
        self.e4.grid(row=3, column=1)

        self.sum_text = StringVar()
        self.e5 = Entry(window, textvariable=self.sum_text)
        self.e5.grid(row=15, column=1)

        #self.window = Listbox(window, height=8, width=35)
        #self.window.grid(row=5, column=0, rowspan=8, columnspan=2)
        #self.window.bind('<<ListboxSelect>>', self.get_selected_row)
        self.list2 = MultiListbox(window,
                                  (('id', 10), ('Product', 20), ('Seller', 20),
                                   ('Price', 20), ('Qty', 10)))
        self.list2.grid(row=6, column=0, rowspan=8, columnspan=2)
        ##        sb1 = Scrollbar(self.list2)
        ##        sb1.grid(row=5, column=2, rowspan=6)
        ##        self.list2.config(yscrollcommand=sb1.set)
        ##        sb1.config(command=self.list2.yview)
        b1 = Button(window,
                    text="View all",
                    width=12,
                    command=self.view_command)
        b1.grid(row=0, column=2)
        # b2 = Button(window, text="Search entry", width=12, command=self.search_command)
        # b2.grid(row=3, column=3)

        b2 = Button(window,
                    text="Add entry",
                    width=12,
                    command=self.add_command)
        b2.grid(row=1, column=2)

        b3 = Button(window,
                    text="Update selected",
                    width=12,
                    command=self.update_command)
        b3.grid(row=2, column=2)

        b4 = Button(window,
                    text="Delete selected",
                    width=12,
                    command=self.delete_command)
        b4.grid(row=3, column=2)

        b5 = Button(window, text="Close", width=12, command=window.destroy)
        b5.grid(row=4, column=2)

    def get_selected_row(
        self, event
    ):  #the "event" parameter is needed b/c we've binded this function to the listbox
        try:
            index = self.list2.curselection()
            self.selected_tuple = self.list2.get(index)
            self.e1.delete(0, END)
            self.e1.insert(END, self.selected_tuple[1])
            self.e2.delete(0, END)
            self.e2.insert(END, self.selected_tuple[2])
            self.e3.delete(0, END)
            self.e3.insert(END, self.selected_tuple[3])
            self.e4.delete(0, END)
            self.e4.insert(END, self.selected_tuple[4])
        except IndexError:
            pass  #in the case where the listbox is empty, the code will not execute

    def view_command(self):
        self.list2.delete(
            0, END
        )  # make sure we've cleared all entries in the listbox every time we press the View all button
        for row in database.view():
            self.list2.insert(END, row)

    # def search_command(self):
    #     self.window.delete(0, END)
    #     for row in database.search(self.title_text.get(), self.author_text.get(), self.year_text.get(), self.ISBN_text.get()):
    #         self.window.insert(END, row)

    def add_command(self):
        database.insert(self.product_text.get(), self.seller_text.get(),
                        self.price_text.get(), self.qty_text.get())
        self.list2.delete(0, END)
        self.list2.insert(END,
                          (self.product_text.get(), self.seller_text.get(),
                           self.price_text.get(), self.qty_text.get()))

    def delete_command(self):
        #database.delete(self.selected_tuple[0])

        window1 = Tk()
        self.label = Label(window1,
                           text="Enter Product Name you want to delete")
        self.label.grid(row=1, column=0)
        self.id_text = StringVar()
        self.entry = Entry(window1, textvariable=self.id_text)
        self.entry.grid(row=2, column=0)
        #self.x=self.name_text.get()
        self.but = Button(window1,
                          text="Delete",
                          width=12,
                          command=database.delete(self.id_text.get()))
        self.but.grid(row=3, column=0)
        self.view_command()
        #l3 = Label(window1, text="Price")
        #l3.grid(row=2, column=0)

    def update_command(self):
        #be careful for the next line ---> we are updating using the texts in the entries, not the selected tuple
        database.update(self.selected_tuple[0], self.product_text.get(),
                        self.seller_text.get(), self.price_text.get(),
                        self.qty_text.get())
        self.view_command()