Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

tm9135

New Coder
Im creating a simple PoS system on python using tk for my GUI, so far i have made a log allowing access to the code and a menu system to go with it. I have also made a SQL database to keep item descriptions linking it to the GUI to create buttons

My issues/criteria:

  • i need the total price display to update when an item is clicked
  • calculate and display tax
  • Print a receipt at the end
  • i also want a sound to play when a button is pressed
  • There is an error with the button used to add items to the stock through the gui
im not sure what else i need but heres the code

import tkinter as tkimport sqlite3with open("login.txt", "w") as f: f - Pastebin.com
 
Although not implemented using tkinter, here is a link to practice script on the forum I wrote a few years ago. Maybe it will help you. It doesn't use sqlite3 either but, both could easily implementeed.
 
Here is an example of one way it could be done. It will create a test database but, no tables are created and no database functions. Purely for example only.

Python:
import tkinter as tk
from tkinter import messagebox
import sqlite3 as sq

class Model:
    def __init__(self):
        db = 'test.db'
        self.connect =  sq.connect(db)

    def create(self):
        '''
            Method for creating database
        '''
        return 'Database created'

    def add(self):
        '''
            Method for adding items
        '''
        return 'Item added to database'
   
    def delete(self):
        '''
            Method for deleting an item from database
        '''
        return 'Item has been deleted from database'
   
    def get_one(self, id):
        '''
            Method for getting one item from database
        '''
        return f'Item returned for display {id}'
   
    def get_all(self):
        '''
            Method for getting all items
        '''
        return 'All items retrieved from database'
   
    def edit(self, id):
        '''
            Method for editing a item in the database
        '''
        return f'Item {id} has been edited'
   

class Window:
    '''
        Class creates the view window
        Create a header label and the listbox
    '''
    def __init__(self, parent):

        label = tk.Label(parent, text='Doubleclick an item')
        label['font'] = (None, 18, 'bold')
        label.pack(fill='x', expand=0, pady=(0,8))
       
       
        self.box = tk.Listbox(parent)
        self.box['font'] = (None, 18, 'normal')
        self.box.pack(fill='both', expand=True)
       

class Controller:
    '''
        Controller class communicates between the View and Model classes
    '''
    def __init__(self, model, window):

        # Instance globals
        self.model = model
        self.window = window

        # Display a message that the database was created
        messagebox.showinfo('Create', self.model.create())
       
        # Setup some mock items for the listbox
        items = [f'item {i+1}' for i in range(10)]

        # Insert the mock items into listbox
        self.window.box.insert(tk.END, *items)

        # Bind left mouse button to items. When double-clicked execute a function
        self.window.box.bind('<Double-Button-1>', self.show)
       

    def show(self, event):
        '''
            Method displays a message when item is double-clicked
        '''
        item = self.window.box.get(self.window.box.curselection())
        messagebox.showinfo('Item click', f'You clicked {item}')


if __name__ == '__main__':
    root = tk.Tk()
    root.geometry('800x600+300+300')
    root['padx'] = 10
    root['pady'] = 10
    controller = Controller(Model(), Window(root))
    root.mainloop()
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom