'Data in Tkinter not updating when running SQLite3 delete from
Alrighty, so I have 3 total functions defined in the project, but when I use the delete command, it will not refresh the other function to show the update to the rows, but when I use the submit command it does refresh. Any Advice? Main goal is that first my_delete(), I included the submit() as that one is correctly updating the show().
Little function to clearly pull information from the database for active trades, seperating the proper information to the columns and rows
def my_delete(self,id):
my_var=tkinter.messagebox.askyesnocancel("DELETE?", "Delete id:"+str(id),icon='warning',default="no")
if my_var:
r_set=c.execute("DELETE FROM openPositions WHERE s_id=" + str(id) )
conn.commit()
tkinter.messagebox.showerror("Deleted ","No of records deleted=" +str(r_set.rowcount))
self.show()
def show(self):
r_set=c.execute("SELECT * FROM openPositions")
i=6
for openPositions in r_set:
for j in range(len(openPositions)):
e = Label(self.master, width=10, text=(openPositions[j]), font=("Helvetica", 12))
e.grid(row=i, column = j + 1, padx=(70,0), pady=(5,0), columnspan=1)
### Close position button to populate for every trade ###
e = Button(self.master, text="Close Position", width=30, command=lambda d=openPositions[0] : self.my_delete(d))
e.grid(row=i, column = 6, padx=(10,0), pady=(5,0), columnspan=3)
i=i+1 # increments for each to next row
### Function for when Button is Pressed ###
def submit(self):
### convert string values to a new variable ##
stk = self.varStk.get()
typ = self.varType.get()
## changing quan and etrPr from string to integer and float values for multiplication ##
quan = int(self.varQuan.get())
entPr = float(self.varEnPr.get())
## multiplying quan and entPr to give us the Position Size for database and submitted text ##
posSize = quan * entPr
## Clearing entered data and resetting drop down menu to buy once button is clicked ##
self.txtStkTik.delete(0, END)
self.txtpos_quan.delete(0, END)
self.txtpos_price.delete(0, END)
self.varType.set("Buy")
## setting variables into an array for easy submitting to database ##
array1 = [stk,typ,quan,entPr,posSize]
## connecto to database and inserting array of variables into database ##
conn.executemany('INSERT INTO openPositions(stock_ticker, entryType, pos_quan, entryPrice, pos_size) VALUES (?,?,?,?,?)', (array1,))
conn.commit()
## pop up message displaying that commit of stock was completed ##
tkinter.messagebox.showinfo("Trade Submitted.", "You submitted {} for {} order in amount of {} share at an entry price of ${} for a total Position Size of ${}".format(stk,typ,quan,entPr,posSize))
#### Copied over the function for writing the information on screen to auto populate info when clicking submit instead of refreshing the app ###
self.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
