2

I'm trying to do this table as a desktop app (not web). It should be an editable table, allowing the user to introduce his own data (inputs), saving it at the database (connected to the database with SQLite) and if there is already some information in the database, show it into the table and not letting the user change it. This makes a table like I want but I don't know how to use grid with it because it takes all screen and I want it below the select list option. Thank you so much! I will let my code below.

from tkinter import ttk
from tkinter import *
from tkcalendar import Calendar, DateEntry

import sqlite3

class Client:

    dbName = 'Database.db' 

    def __init__(self, window):
        self.wind = window
        self.wind.title('Aplicación cliente')

    #Container
        frame = LabelFrame(self.wind, text = 'Registrar un nuevo cliente')
        frame.grid(row=0, column=0, columnspan=1, padx=20, pady=20)

    #Name input
        Label(frame, text = 'Nombre: ').grid(row=1, column=0)
        self.name = Entry(frame)
        self.name.focus
        self.name.grid(row=1, column=1, padx=10, pady=5)

    #Birth date input
        Label(frame, text = 'Fecha de nacimiento: ').grid(row=2, column=0)
        self.calendar = DateEntry(frame,width=30,bg="darkblue",fg="white")
        self.calendar.grid(row=2, column=1, padx=10, pady=5)

        Label(frame, text = 'Fecha de bautismo: ').grid(row=3, column=0)
        self.calendar = DateEntry(frame,width=30,bg="darkblue",fg="white")
        self.calendar.grid(row=3, column=1, padx=10, pady=5)

    #Select list
        var = StringVar()

        Label(frame, text = 'Grupo: ').grid(row=4, column=0)
        self.dropdownList = OptionMenu(frame, var, 'Hombre', 'Mujer', 'Anciano', 'Siervo ministerial', 'Precursor regular', 'Ungido', 'Otras ovejas')
        self.dropdownList.grid(row=4, column=1, padx=10, pady=5)

        rows = []
        for i in range(12):
            cols = []
            for j in range(7):
                e = Entry(relief=RIDGE)
                e.grid(row=i, column=j, sticky=NSEW)
                e.insert(END, '%d.%d' % (i, j))
                cols.append(e)
            rows.append(cols)
            
        def onPress():
            for row in rows:
                for col in row:
                    print(col.get())
                print
        
        Button(text='Fetch', command=onPress).grid()

    def run_query(self, query, parameters=()):
        with sqlite3.connect(self.dbName) as conn:
            cursor = conn.cursor()
            result = cursor.execute(query, parameters)
            conn.commit()
        return result

    def getClient(self):

        records = self.tree.get_children()
        for element in records:
            self.tree.delete(element)

        query = 'SELECT * FROM Client'
        dbRows = self.run_query(query)
        for row in dbRows:
            self.tree.insert('',0, text=row[1], values=row[2])

if __name__ == '__main__':
    window = Tk()
    application = Client(window)
    window.mainloop()
  • 2
    _"any guide would be helpful"_ isn't an appropriate type of question for stackoverflow. You need to be more specific about what type of help you need. – Bryan Oakley Jul 23 '20 at 14:35
  • Thanks @BryanOakley I already edited it. I hope it is more clear now. – Yomira Martínez Jul 23 '20 at 14:40
  • Requests for links to tutorials and documentation is also off topic for stackoverflow. – Bryan Oakley Jul 23 '20 at 14:41
  • Welcome to stackoverflow, as Bryan says, here accepted questions have to be more specific/technical. Once you try something out if you get errors, or blocked,..., then that is something that you can find help here. About "I don't know how to post it well," you can take a look at https://stackoverflow.com/help/how-to-ask – J.J Jul 23 '20 at 14:51
  • 1
    I changed it and asked for something more specific now, let me know if it is okay now, Thanks once again @BryanOakley – Yomira Martínez Jul 23 '20 at 14:51
  • Thanks @Juan, I never saw that post so it is really helpful! – Yomira Martínez Jul 23 '20 at 14:53

0 Answers0