I've seen multiple other answers to this question, which includes solutions such as adding Canvas and Frames, but every time I try to do that, the checkbuttons do not display in my window.
This code is basically to display a window with chrome history listed with checkbuttons and allow the user to select what they want to delete. When they scroll down and click the Delete button, the history is cleared.
I've managed to make everything except for the scrollbar work.
import sqlite3
import os
from tkinter import *
path = os.path.expanduser('~/AppData/Local/Google/Chrome/User Data/Default/History')
conn = sqlite3.connect(path)
cur = conn.cursor()
select_statement = "SELECT urls.url FROM urls, visits WHERE urls.id = visits.url;"
cur.execute(select_statement)
results = cur.fetchall()
root = Tk()
text = root
# window title
title = Label(root,text = "Check the websites you want to delete : \n", justify = LEFT)
title.grid(row=1,column=0)
# Removing the files from the sql database
ids=[]
def delHis():
global cbs
for name, checkbutton in cbs.items():
if checkbutton.var.get():
for rows in cur.execute('''SELECT urls.id,urls.url FROM urls,visits WHERE urls.id = visits.url AND urls.url = (?); ''', [checkbutton['text']]):
print(rows)
id = rows[0]
ids.append((id,))
cur.executemany('''DELETE FROM visits WHERE id = ?''', ids)
cur.executemany('''DELETE FROM urls WHERE id = ?''', ids)
conn.commit()
# Creating the checkbuttons
cbs = dict()
for i,value in enumerate(results):
cbs[value] = Checkbutton(text, text = value, onvalue=True,offvalue=False, wraplength=500, )
cbs[value].var = BooleanVar(text, value=False)
cbs[value]['variable'] = cbs[value].var
cbs[value].grid(row=i+3, column=0)
# delete button that links to delHis()
button = Button(text, text='Delete')
button.config(height = 2, width = 50, bg = '#ff6666', fg = '#ffffff', command=delHis)
try:
button.grid(row=i+8, column=0)
except:
title = Label(text, text="History is empty", justify=LEFT)
title.pack()
text.grid()
root.mainloop()
I'm pretty new to all this, so please be specific. Thank you.