Beispiel #1
0
 def _init_gridbox(self):
     self.mlb = MultiListbox(self.frame,
                             (('id #', 5), ('Customer', 25), ('Date', 15),
                              ('Grand Total', 15)))
     tbproducts = sql.session._query("select * from invoices")
     self.update_mlb(tbproducts)
     self.mlb.pack(expand=YES, fill=BOTH)
Beispiel #2
0
class LookupList:
    def __init__(self, master):
        self.frame = Frame(master)
        self.le_frame = Frame(self.frame)
        self.tblookup = sql.session
        lbl = Label(self.le_frame, text="vehicle").pack(side=LEFT)
        self.ent = Entry(self.le_frame)
        self.ent.pack(side=LEFT)
        self.ent.bind("<KeyRelease>",
                      self.txtchange)  # <Key>",self.keypressed)
        self.le_frame.pack(side=TOP)
        self._init_gridbox()
        self.frame.pack(side=TOP, expand=NO)

    def _init_gridbox(self):
        self.mlb = MultiListbox(self.frame, (('id #', 5), ('Vehicle', 20),
                                             ('Type', 30), ('UnitPrice', 15)))
        self.update_mlb('')
        self.mlb.not_focus()
        self.mlb.pack(expand=YES, fill=BOTH, side=TOP)

    def txtchange(self, event):
        txtent = self.ent.get()
        self.update_mlb(txtent)

    def update_mlb(self, val):
        x = self.tblookup._query("select * from products where name like '%" +
                                 val + "%' order by name")
        self.mlb.delete(0, END)
        for row in x:
            self.mlb.insert(END, (int(row[0]), row[1], row[2], int(row[3])))
        self.mlb.selection_set(
            0)  # setting first of the rows which is selected
Beispiel #3
0
 def _init_gridbox(self):
     self.mlb = MultiListbox(self.frame,
                             (('id #', 3), ('Product', 25),
                              ('Description', 25), ('Price', 12),
                              ('PlateNumber', 10), ('Year', 12)))
     tbproducts = sql.session._query("select * from products")
     self.update_mlb(tbproducts)
     self.mlb.pack(expand=YES, fill=BOTH)
Beispiel #4
0
class FormInvoices:
    """TopLevel widget for browsing, adding and editing invoices here in the GUI and into sql."""
    def __init__(self):
        self.frame = Toplevel()
        _init_toolbar(self)
        self._init_gridbox()
        self.frm_addinvoice = None
        self.addinvoiceflag = False
        self.editinvoiceflag = False

    def _init_gridbox(self):
        self.mlb = MultiListbox(self.frame,
                                (('id #', 5), ('Customer', 25), ('Date', 15),
                                 ('Total Amount', 15)))
        tbvehicles = sql.session._query("select * from invoices")
        self.update_mlb(tbvehicles)
        self.mlb.pack(expand=YES, fill=BOTH)

    def update_mlb(self, tb):
        self.mlb.delete(0, END)
        for row in tb:
            self.mlb.insert(END, (int(row[0]), row[1], row[2], int(row[3])))
        self.mlb.selection_set(0)  # set first row selected

    def btn_add_click(self):
        print('check if addwindow exist. If not, cmd will inform about it')
        if self.addinvoiceflag: return 0
        print('not existing')
        self.addinvoiceflag = True
        self.frm_addinvoice = FormAddInvoice()
        self.frame.wait_window(self.frm_addinvoice.master)
        print('form addinvoice does not exist. Add button will work')
        self.addinvoiceflag = False

    def btn_edit_click(self):
        if self.editinvoiceflag: return 0
        self.editinvoiceflag = True
        self.frm_editinvoice = FormEditInvoice()
        self.frm_editinvoice.init_entryboxes(
            self.mlb.item_selected[1:])  # (id,customer,date,amount)
        tbinvitems = sql.session._show_invoice(self.mlb.item_selected[1])
        self.frm_editinvoice.update_mlbitems(tbinvitems)
        self.frame.wait_window(self.frm_editinvoice.master)
        self.editinvoiceflag = False

    def btn_del_click(self):
        if self.mlb.item_selected == None: return 'please select first'
        print(self.mlb.item_selected[1])
        sql.session._delete_invoice(int(self.mlb.item_selected[1]))
        self.mlb.delete(self.mlb.item_selected[0])
        self.mlb.item_selected = None

    def btn_find_click(self):
        print('find')
Beispiel #5
0
class FormCustomers:
    # The Vehicles window with toolbar and a datagrid

    def __init__(self):
        self.frame = Toplevel()
        _init_toolbar(self)
        self._init_gridbox()
        self.frm_addcustomers = None
        self.frm_editcustomers = None
        self.addcustomersflag = False  # frmaddproduct doesn't exist

    def _init_gridbox(self):
        self.mlb = MultiListbox(self.frame, (('cusid #', 3), ('cusname', 25),
                                             ('cusad', 25)))
        tbcustomers = sql.session._query("select * from customers")
        self.update_mlb(tbcustomers)
        self.mlb.pack(expand=YES, fill=BOTH)

    # button is clicked() for form add vehicles
    def btn_add_click(self):
        if self.addcustomersflag: return 0
        print('not exist')
        self.addcustomersflag = True
        self.frm_addcustomer = FormAddCustomer()
        self.frame.wait_window(self.frm_addcustomer.frame)
        if self.frm_addcustomer._okbtn_clicked == 1:
            tbcustomers = sql.session._query("select * from customers")
            self.update_mlb(tbcustomers)
        self.addcustomerflag = False

    def btn_edit_click(self):
        print('edit')

    def btn_del_click(self):
        if self.mlb.item_selected == None:
            return 'Could you select first one, please?'
        print(self.mlb.item_selected[1])
        sql.session._delete_product(int(self.mlb.item_selected[1]))
        self.mlb.delete(self.mlb.item_selected[0])
        self.mlb.item_selected = None

    def btn_find_click(self):
        fnd = self.entryfind.get()

        tbcustomers = sql.session._find_customers(fnd)
        self.update_mlb(tbcustomers)

    def update_mlb(self, tb):
        self.mlb.delete(0, END)
        # tbproducts=sql.session._query(q)
        for row in tb:
            self.mlb.insert(END, (
                int(row[0]),
                row[1],
                row[2],
            ))
Beispiel #6
0
class FormVehicles:
    '''The Vehicles window with toolbar and a datagrid of cars'''
    def __init__(self):
        self.frame = Toplevel()
        _init_toolbar(self)
        self._init_gridbox()
        self.frm_addvehicle = None
        self.frm_editvehicle = None
        self.addvehicleflag = False

    def _init_gridbox(self):
        self.mlb = MultiListbox(self.frame,
                                (('id #', 3), ('vehicle', 25),
                                 ('Description', 25), ('Price', 12),
                                 ('PlateNumber', 10), ('Year', 12)))
        tbvehicles = sql.session._query("select * from vehicles")
        self.update_mlb(tbvehicles)
        self.mlb.pack(expand=YES, fill=BOTH)

    # form vehicles add button clicked()
    def btn_add_click(self):
        if self.addvehicleflag: return 0
        print('not exist')
        self.addvehicleflag = True
        self.frm_addvehicle = FormAddvehicle()
        self.frame.wait_window(self.frm_addvehicle.frame)
        if self.frm_addvehicle._okbtn_clicked == 1:
            tbvehicle = sql.session._query("select * from vehicles")
            self.update_mlb(tbvehicle)
        self.addvehicleflag = False

    #ToDo
    def btn_edit_click(self):
        print('edit')

    def btn_del_click(self):
        if self.mlb.item_selected == None: return 'please select first'
        print(self.mlb.item_selected[1])
        sql.session._delete_vehicle(int(self.mlb.item_selected[1]))
        self.mlb.delete(self.mlb.item_selected[0])
        self.mlb.item_selected = None

    #ToDo
    def btn_find_click(self):
        fnd = self.entryfind.get()

        tbvehicles = sql.session._find_vehicles(fnd)
        self.update_mlb(tbvehicles)

    def update_mlb(self, tb):
        self.mlb.delete(0, END)
        for row in tb:
            self.mlb.insert(
                END,
                (int(row[0]), row[1], row[2], int(row[3]), row[4], row[5]))
Beispiel #7
0
class FormEditInvoice:
    def __init__(self):
        self.master = Toplevel()
        self.frame1 = Frame(self.master)
        label_entry(self.frame1, 'Invoice#:')
        self.frame1.pack(side=TOP)

        self.frame2 = Frame(self.master)
        label_entry(self.frame2, 'Customer:', 'Date:')
        self.frame2.pack(side=TOP)

        lblprod = Label(self.master, text='Items').pack(side=TOP)
        self.frame3 = Frame(self.master)
        self.mlbitems = MultiListbox(self.frame3,
                                     (('LN#', 5), ('Vehicle', 15),
                                      ('Quantity', 5), ('Type', 20),
                                      ('UnitPrice', 10), ('Total', 10)))
        self.mlbitems.not_focus()
        self.mlbitems.pack(expand=YES, fill=BOTH, side=TOP)
        self.frame3.pack(side=TOP)

        self.frame4 = Frame(self.master)
        label_entry(self.frame4, 'Total amount:')
        self.frame4.pack(side=TOP)

    def init_entryboxes(self, val):
        self.frame1._entry.insert(END, val[0])
        self.frame1._entry['state'] = DISABLED

        self.frame2._entry.insert(END, val[1])
        self.frame2._entry2.insert(END, val[2])
        self.frame2._entry['state'] = DISABLED
        self.frame2._entry2['state'] = DISABLED

        self.frame4._entry.insert(END, val[3])
        self.frame4._entry['state'] = DISABLED

    def update_mlbitems(self, invitems):
        self.mlbitems.delete(0, END)
        for row in invitems:
            self.mlbitems.insert(
                END, (row[0], row[1], row[2], row[3], row[4], row[5]))
        self.mlbitems.selection_set(
            0)  # setting the first row which is selected
Beispiel #8
0
    def __init__(self):
        self.master = Toplevel()
        self.frame1 = Frame(self.master)
        label_entry(self.frame1, 'Invoice#:')
        self.frame1.pack(side=TOP)

        self.frame2 = Frame(self.master)
        label_entry(self.frame2, 'Customer:', 'Date:')
        self.frame2.pack(side=TOP)

        lblprod = Label(self.master, text='Items').pack(side=TOP)
        self.frame3 = Frame(self.master)
        self.mlbitems = MultiListbox(self.frame3,
                                     (('LN#', 5), ('Vehicle', 15),
                                      ('Quantity', 5), ('Type', 20),
                                      ('UnitPrice', 10), ('Total', 10)))
        self.mlbitems.not_focus()
        self.mlbitems.pack(expand=YES, fill=BOTH, side=TOP)
        self.frame3.pack(side=TOP)

        self.frame4 = Frame(self.master)
        label_entry(self.frame4, 'Total amount:')
        self.frame4.pack(side=TOP)
                state='disabled')
btnAdd.grid(row=9, column=0)
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'),
Beispiel #10
0
                  width=10,
                  text="Reset",
                  bg="gray",
                  command=Reset,
                  padx=10,
                  pady=10).grid(row=10, column=1)
#btncheckout=Button(f1,bd=20,fg="black",bg="light green",font=('arial',16,'bold'),width=10,text="Total",command=checkout,padx=10,pady=10).grid(row=9,column=1)
#btnExit=Button(f1,bd=20,fg="white",font=('arial',16,'bold'),width=10,text="Exit",bg="gray",command=qExit,padx=10,pady=10).grid(row=10,column=0)
#btnAdd=Button(f1,bd=20,fg="black",font=('arial',16,'bold'),width=10,text="Add",bg="light blue",command=mAdd,padx=10,pady=10,state='disabled')
#btnAdd.grid(row=9,column=0)
#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, (('Book Name', 20), ('Quantity', 20), ('Cost', 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'),
Beispiel #11
0
 def _init_gridbox(self):
     self.mlb = MultiListbox(self.frame, (('cusid #', 3), ('cusname', 25),
                                          ('cusad', 25)))
     tbcustomers = sql.session._query("select * from customers")
     self.update_mlb(tbcustomers)
     self.mlb.pack(expand=YES, fill=BOTH)
Beispiel #12
0
 def _init_gridbox(self):
     self.mlb = MultiListbox(self.frame, (('id #', 5), ('Vehicle', 20),
                                          ('Type', 30), ('UnitPrice', 15)))
     self.update_mlb('')
     self.mlb.not_focus()
     self.mlb.pack(expand=YES, fill=BOTH, side=TOP)
Beispiel #13
0
    def _init_widgets(self):
        self.frame0 = Frame(self.master)
        label_entry(self.frame0, 'Invoice# :')
        rowid = sql.session._next_invoiceid()
        self.frame0._entry.insert(END, str(rowid))
        self.frame0._entry['state'] = DISABLED
        self.frame0.pack(side=TOP)
        # frame1- lblinvoice, lbl_date, btn_date
        self.frame1 = Frame(self.master)
        label_entry(self.frame1, 'Customer:')
        self.lbl_date = Label(self.frame1,
                              text='Date:' + str(datetime.today())[:10])
        self.lbl_date.pack(side=LEFT)
        self.btn_date = Button(self.frame1,
                               text="PickDate",
                               width=8,
                               command=self.btn_date_click)
        self.btn_date.pack(side=LEFT)
        self.frame1.pack(side=TOP)

        # frame2: lookuplist
        self.frame2 = LookupList(self.master)
        self.frame2.ent.focus()  # focusing to entry vehicle

        # frame3- quantity, ent_qty, btn_additem
        self.frame3 = Frame(self.master)
        self.lbl3_1 = Label(self.frame3, text="Quantity")
        self.lbl3_1.pack(side=LEFT)
        self.ent_qty = Entry(self.frame3)
        self.ent_qty.pack(side=LEFT)
        self.btn_additem = Button(self.frame3,
                                  text="AddItem",
                                  width=8,
                                  command=self.btn_additem_click)
        self.btn_additem.pack(side=LEFT)
        self.frame3.pack(side=TOP)

        # frame4- mlbitems
        self.frame4 = Frame(self.master)
        self.mlbitems = MultiListbox(self.frame4,
                                     (('LN#', 4), ('ID#', 6), ('Product', 15),
                                      ('Quantity', 5), ('Description', 20),
                                      ('UnitPrice', 10), ('Total', 10)))
        self.mlbitems.not_focus()  # don't take_focus
        self.mlbitems.pack(expand=YES, fill=BOTH, side=TOP)
        self.frame4.pack(side=TOP)

        # frame5-netamount-stringvar, paid, balance
        self.frame5 = Frame(self.master)
        self.lbl5_1 = Label(self.frame5, text="Net:")
        self.lbl5_1.pack(side=LEFT)
        self.netamount = StringVar()
        self.netamount.set('0')
        self.lbl5_2 = Label(self.frame5,
                            textvariable=self.netamount,
                            font=("Helvetica", 16))
        self.lbl5_2.pack(side=LEFT)
        self.lbl5_3 = Label(self.frame5, text="paid:")
        self.lbl5_3.pack(side=LEFT)
        self.ent_paid = Entry(self.frame5)
        self.ent_paid.pack(side=LEFT)
        self.ent_paid.bind("<KeyRelease>", self.ent_paid_change)
        self.balanceamount = StringVar()
        self.lbl5_4 = Label(self.frame5, text="Balance: ").pack(side=LEFT)
        # self.balanceamount.set('balance:')
        self.lblbal = Label(self.frame5,
                            textvariable=self.balanceamount,
                            foreground='red',
                            font=("Helvetica", 22)).pack(side=LEFT)

        self.frame5.pack(side=TOP)

        self.btn_ok = Button(self.master,
                             text="OK",
                             width=7,
                             command=self.btnok_click)
        self.btn_ok.pack(side=TOP)
Beispiel #14
0
class FormAddInvoice:
    '''New vehicles, three labels, three textboxes, OK button are added'''
    def __init__(self):

        self.master = Toplevel()
        self.master.protocol("WM_DELETE_WINDOW", self.callback)  # user quits
        self._init_widgets()

    def _init_widgets(self):
        self.frame0 = Frame(self.master)
        label_entry(self.frame0, 'Invoice# :')
        rowid = sql.session._next_invoiceid()
        self.frame0._entry.insert(END, str(rowid))
        self.frame0._entry['state'] = DISABLED
        self.frame0.pack(side=TOP)
        # frame1- lblinvoice, lbl_date, btn_date
        self.frame1 = Frame(self.master)
        label_entry(self.frame1, 'Customer:')
        self.lbl_date = Label(self.frame1,
                              text='Date:' + str(datetime.today())[:10])
        self.lbl_date.pack(side=LEFT)
        self.btn_date = Button(self.frame1,
                               text="PickDate",
                               width=8,
                               command=self.btn_date_click)
        self.btn_date.pack(side=LEFT)
        self.frame1.pack(side=TOP)

        # frame2: lookuplist
        self.frame2 = LookupList(self.master)
        self.frame2.ent.focus()  # focusing to entry vehicle

        # frame3- quantity, ent_qty, btn_additem
        self.frame3 = Frame(self.master)
        self.lbl3_1 = Label(self.frame3, text="Quantity")
        self.lbl3_1.pack(side=LEFT)
        self.ent_qty = Entry(self.frame3)
        self.ent_qty.pack(side=LEFT)
        self.btn_additem = Button(self.frame3,
                                  text="AddItem",
                                  width=8,
                                  command=self.btn_additem_click)
        self.btn_additem.pack(side=LEFT)
        self.frame3.pack(side=TOP)

        # frame4- mlbitems
        self.frame4 = Frame(self.master)
        self.mlbitems = MultiListbox(self.frame4,
                                     (('LN#', 4), ('ID#', 6), ('Product', 15),
                                      ('Quantity', 5), ('Description', 20),
                                      ('UnitPrice', 10), ('Total', 10)))
        self.mlbitems.not_focus()  # don't take_focus
        self.mlbitems.pack(expand=YES, fill=BOTH, side=TOP)
        self.frame4.pack(side=TOP)

        # frame5-netamount-stringvar, paid, balance
        self.frame5 = Frame(self.master)
        self.lbl5_1 = Label(self.frame5, text="Net:")
        self.lbl5_1.pack(side=LEFT)
        self.netamount = StringVar()
        self.netamount.set('0')
        self.lbl5_2 = Label(self.frame5,
                            textvariable=self.netamount,
                            font=("Helvetica", 16))
        self.lbl5_2.pack(side=LEFT)
        self.lbl5_3 = Label(self.frame5, text="paid:")
        self.lbl5_3.pack(side=LEFT)
        self.ent_paid = Entry(self.frame5)
        self.ent_paid.pack(side=LEFT)
        self.ent_paid.bind("<KeyRelease>", self.ent_paid_change)
        self.balanceamount = StringVar()
        self.lbl5_4 = Label(self.frame5, text="Balance: ").pack(side=LEFT)
        # self.balanceamount.set('balance:')
        self.lblbal = Label(self.frame5,
                            textvariable=self.balanceamount,
                            foreground='red',
                            font=("Helvetica", 22)).pack(side=LEFT)

        self.frame5.pack(side=TOP)

        self.btn_ok = Button(self.master,
                             text="OK",
                             width=7,
                             command=self.btnok_click)
        self.btn_ok.pack(side=TOP)

    def add_item(self):
        qty = self.ent_qty.get()
        if qty == '':
            print('no quantity set')
            return 0
        qty = int(qty)
        LN = self.mlbitems.size() + 1
        r, i_d, prdct, desc, price = self.frame2.mlb.item_selected
        self.mlbitems.insert(END,
                             (LN, i_d, prdct, qty, desc, price, price * qty))
        net_amt = int(self.netamount.get()) + (price * qty)
        self.netamount.set(str(net_amt))
        self.frame2.ent.delete(0, END)  # clear entry vehicle
        self.ent_qty.delete(0, END)  # clear enter field for quantity
        self.frame2.ent.focus()  # focusing vehicle entry field

    def btn_date_click(self):
        print('date')

    def ent_paid_change(self, event):
        paid = self.ent_paid.get()
        if paid == '':
            return 0
        bal = int(paid) - int(self.netamount.get())
        self.balanceamount.set(str(bal))

    def btn_additem_click(self):
        self.add_item()

    def btnok_click(self):
        no_of_items = self.mlbitems.size()
        if no_of_items == 0:
            print('please select your vehicles first')
            return '0'
        print('okbutton clicked')
        i_d = int(self.frame0._entry.get())  # invoiceid
        tbinvitems_items = []
        for item in range(no_of_items):
            temp1 = self.mlbitems.get(item)
            tbinvitems_items.append((
                temp1[0],
                i_d,
                temp1[1],
                temp1[3],
            ))

        tbinv_item = (i_d, self.frame1._entry.get(),
                      str(datetime.today())[:10], int(self.netamount.get()))
        sql.session._add_invoice(tbinv_item, tbinvitems_items)
        self._okbtn_clicked = 1
        print('operator quit by clicking ok button')
        self.master.destroy()

    def callback(self):

        self._okbtn_clicked = 0
        print('operator close window')
        self.master.destroy()
Beispiel #15
0
    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)
Beispiel #16
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()