Trying to store user input into array and database at the same time Trying to store user input into array and database at the same time tkinter tkinter

Trying to store user input into array and database at the same time


Explanation:

Your mistakes is that your list will be set to empty list each time the function is run, so since the list is empty, len(list) will be 0 and hence the loop will run 0 times(ineffective), and your list will remain to be empty.

Solution:

What you can do here is, start by moving your list inside __init__, so:

def __init__(self,root):    # Rest of code...    self.venue = []    # Rest of code...

Now there are two ways to proceed, take the recently added values from database and append to list OR you could insert the same tuple of values into the list.

Here, I will just show you how to insert into database and then to a list, because other method requires if conditions and more.

def adddetails(self):    try:        con = pymysql.connect(host="localhost",user="root",password="",database="timetable")        cur = con.cursor()        values = (self._num.get(),self._seatCap.get(),self.time.get(),self.lecturer.get(),self.subject.get(),self.department.get())        cur.execute("insert into timetablelist (venue,venuepax,time,lecturer,module,department) values(%s,%s,%s,%s,%s,%s)",values)        con.commit()        con.close()        messagebox.showinfo("Success","Details Added to Timetable",parent=self.root)                self.avenue.append(values)        # Rest of code...

So your list will be in the form of:

[(n1,n2,n3,...),(a1,a2,a3,...),..] # print(self.avenue)