Why aren't the checkboxes working? On tkinter, python, the ticked checkboxes should be removed from the list but the code isnt understanding 'checked'
import tkinter
from functools import partial
item = 0
list_of_days = [["Monday", "Monday's To do list:", "07:00 - Thomas Ryan: Bed Help",
"08:00 - Nora Jones: Bed Help", "09:00 - Gwendoline Evans: Wash", "10:00 - Ray Roberts:
Wash",
"11:00 - Aylen Matthews: Wash", "12:00 - Roger Vincent: Tablets", "13:00
- Marion Angel: Food Shop", "14:00 - Theodore Davies: Cook", "15:00 - Aylen Matthew:
Tablets"
, "16:00 - Tegwen Anton: Tablets", "17:00 - Edward Stuart: Tablets",
"18:00 - Robert Thomas: Cook", "19:00 - Theodore Davies: Cook","20:00 - Thomas Ryan: Bed
Help"
,"21:00 - Nora Jones: Bed Help"],
["Tuesday", "Tuesday's To do list:", "07:00 - Thomas Ryan: Bed Help",
"08:00 - Nora Jones: Bed Help", "09:00 - Gwendoline Evans: Wash",
"12:00 - Roger Vincent: Tablets", "14:00 - Theodore Davies: Cook",
"15:00 - Aylen Matthew: Tablets"
, "16:00 - Tegwen Anton: Tablets", "17:00 - Edward Stuart: Tablets",
"18:00 - Robert Thomas: Cook", "19:00 - Theodore Davies: Cook","20:00 - Thomas Ryan: Bed
Help"
,"21:00 - Nora Jones: Bed Help"],
["Wednesday", "Wednesday's To do list:", "07:00 - Thomas Ryan: Bed
Help", "08:00 - Nora Jones: Bed Help", "09:00 - Gwendoline Evans: Wash", "10:00 - Ray
Roberts: Wash",
"11:00 - Aylen Matthew: Wash", "12:00 - Roger Vincent: Tablets", "14:00
- Theodore Davies: Cook", "15:00 - Aylen Matthew: Tablets"
, "16:00 - Tegwen Anton: Tablets", "17:00 - Edward Stuart: Tablets",
"18:00 - Robert Thomas: Cook", "19:00 - Theodore Davies: Cook","20:00 - Thomas Ryan: Bed
Help"
,"21:00 - Nora Jones: Bed Help"],
["Thursday", "Thursday's To do list:", "07:00 - Thomas Ryan: Bed Help",
"08:00 - Nora Jones: Bed Help", "09:00 - Gwendoline Evans: Wash", "12:00 - Roger Vincent: Tablets", "14:00 - Theodore Davies: Cook", "15:00 - Aylen Matthew: Tablets" , "16:00 - Tegwen Anton: Tablets", "17:00 - Edward Stuart: Tablets", "18:00 - Robert Thomas: Cook", "19:00 - Theodore Davies: Cook","20:00 - Thomas Ryan: Bed Help" ,"21:00 - Nora Jones: Bed Help"], ["Friday", "Friday's To do list:", "07:00 - Thomas Ryan: Bed Help", "08:00 - Nora Jones: Bed Help", "10:00 - Ray Roberts: Wash", "11:00 - Aylen Matthew: Wash", "12:00 - Roger Vincent: Tablets", "13:00 - Marion Angel: Food Shop", "14:00 - Theodore Davies: Cook", "15:00 - Aylen Matthew: Tablets" , "16:00 - Tegwen Anton: Tablets", "17:00 - Edward Stuart: Tablets", "18:00 - Robert Thomas: Cook", "19:00 - Theodore Davies: Cook","20:00 - Thomas Ryan: Bed Help" ,"21:00 - Nora Jones: Bed Help"]] def remove(check_vars, windowsix, day): checked = 1 counter = 0 for each_item in check_vars: checked = each_item.get() print("each item: ", each_item, "checked: " , checked)
if checked == 1:
del list_of_days[counter]
print("This day: " , list_of_days[day])
counter = counter + 1
windowsix.destroy()
particular_day(day)
def particular_day(day):
print("--------------------------------")
check_vars = []
windowsix = tkinter.Tk()
windowsix.geometry("1000x800")
windowsix.title(list_of_days[day][0])
counter = 0
check_var = ""
for item in list_of_days[day]:
check_var = 1
#check_var = counter
check_var = tkinter.IntVar()
print("CHECK VAR: ", check_var)
check_vars.append(check_var)
# check_box = tkinter.Checkbutton(windowsix, text = list_of_days[day][2:17]
[counter], variable = check_var, onvalue=1,offvalue = 0)
check_box = tkinter.Checkbutton(windowsix, text = list_of_days[day][counter],
variable=check_var, onvalue=1, offvalue=0)
check_box.deselect()
check_box.grid(row = counter, column = 0)
counter = counter + 1
# for item in list_of_days[day]:
# to_do_list = tkinter.Label(windowsix, text = str() + item)
# to_do_list.grid(row=counter,column = 1)
# counter = counter+1
for each_item in check_vars:
checked = each_item.get()
print("each item: ", each_item, "checked: " , checked)
if checked == 1:
del list_of_days[counter]
print("This day: " , list_of_days[day])
counter = counter + 1
#
task_complete_button = tkinter.Button(windowsix, text = "Task Complete", command =
partial(remove, check_vars, windowsix, day),fg= 'black', bg='red')
task_complete_button.grid(row=0, column = 1)
go_back_button = tkinter.Button(windowsix, fg='blue', bg='white', text = "Go Back",
command = windowsix.destroy)
go_back_button.grid(row=0, column=2)
day_label = tkinter.Label(windowsix, text="Day: " + list_of_days[day][0])
day_label.grid(row=0, column =0)
def days_of_week_window():
counter = 0
gui = tkinter.Tk()
gui.geometry("500x500")
gui.title("Days of the Week")
for row in list_of_days:
day_label = tkinter.Label(gui, text = "Day: ")
button = tkinter.Button(gui, text=str(row[0]), command = partial(particular_day,
counter))
go_back_button = tkinter.Button(gui, fg='blue', bg='white',text="Go Back ",
command = gui.destroy)
day_label.grid(row = counter, column =1)
button.grid(row=counter, column =2)
go_back_button.grid(row=6, column=3)
counter = counter + 1
windowone = tkinter.Tk()
windowone.geometry('500x500')
windowone.title("Care Agency")
checklist_button = tkinter.Button(windowone, text = "Checklist", command =
days_of_week_window)
checklist_button.grid(row=0, column=1)"'
Aucun commentaire:
Enregistrer un commentaire