![]() |
Creating a deselect button - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Creating a deselect button (/thread-42144.html) |
Creating a deselect button - dwayne091 - May-18-2024 Am trying to create a deselect button to deselect the checkbuttons all at once any ideas on how to do It? My code from tkinter import * from tkinter import ttk from tkinter import messagebox import os import openpyxl import tkinter as tk from tkinter import Button window = tk.Tk() window.geometry('2200x820') MainFrame = tk.Frame(window, width=385, height=460, relief='raised', borderwidth=1) ButtonFrame = tk.Frame(MainFrame, width=375, height=30, relief='raised', borderwidth=1) LabelFrame = tk.Frame(MainFrame, width=375, height=1, relief='raised', background="yellow", borderwidth=0) LabelFrame1 = tk.Frame(MainFrame, width=375, height=1, relief='raised', background="yellow", borderwidth=0.5) some_button = tk.Button(ButtonFrame, text='Enter data', command=window.destroy) values1 = ["Shein", "Pretty Little Thing","Mangnopop","Ru21","forever21","blunotes","Streetwearsociety","Saints","Charllote Russe","Fashionnova","Capella", "lulus","Missguide"] values = ["Shein", "Pretty\n Little Thing","Mangnopop","Ru21","forever21","blunotes","Streetwearsociety","Saints","Charllote Russe","Fashionnova","Capella", "lulus","Missguide"] combobox = ttk.Combobox(ButtonFrame, width=30) combobox1 = ttk.Combobox(ButtonFrame, width=30) combobox.grid(row=1,column=2,padx=10) combobox1.grid(row=2,column=2) checkbuttons_vars = [tk.BooleanVar() for value in values] checkbuttons_vars1 = [tk.BooleanVar() for value in values1] checkbuttons = [] checkbuttons1 = [] for index, value in enumerate(values): checkbutton = tk.Checkbutton(LabelFrame,text=value, variable=checkbuttons_vars[index]) checkbutton.config(background="yellow", fg="black", font=("Fira Code", 8), selectcolor="white", relief="flat", padx=1, pady=1) checkbutton.pack(side="left",anchor="w",fill="both") checkbuttons.append(checkbutton) for index, value in enumerate(values1): checkbutton = tk.Checkbutton(LabelFrame1,text=value,offvalue = 0, variable=checkbuttons_vars1[index]) checkbutton.config(background="yellow", fg="black", font=("Fira Code", 8), selectcolor="white", relief="flat", padx=1, pady=1) checkbutton.pack(side="left",anchor="w",fill="both") checkbuttons1.append(checkbutton) def update_combobox(): selected_values = [value for value, var in zip(values, checkbuttons_vars,) if var.get()] selected_values1 = [value for value, var in zip(values1, checkbuttons_vars1,) if var.get()] combobox.configure(width=40, height=7) combobox.delete(0, tk.END) combobox.insert(0," , " .join(selected_values,)) combobox.insert(0," , ") combobox.insert(0," , ".join(selected_values1)) def update_combobox1(): selected_values = [value for value, var in zip(values, checkbuttons_vars) if var.get()] selected_values1 = [value for value, var in zip(values1, checkbuttons_vars1,) if var.get()] combobox1.configure(width=40, height=7) combobox1.delete(0, tk.END) combobox1.insert(0, ", ".join(selected_values)) combobox1.insert(0," , ") combobox1.insert(0," , ".join(selected_values1)) update_button = tk.Button(ButtonFrame, text="Update", anchor="nw",command=update_combobox) update_button.grid(row=1,column=3) update_button1 = tk.Button(ButtonFrame, text="Update", anchor="nw",command=update_combobox1) update_button1.grid(row=2,column=3) for frame in [MainFrame, LabelFrame, LabelFrame1, ButtonFrame,]: frame.pack(expand=True, fill='both') frame.pack_propagate(0) for widgetin [some_button]: widget.pack(expand=True, fill='x', anchor='s',ipady=10) window.mainloop() RE: Creating a deselect button - Gribouillis - May-18-2024 You could use this after update_button1.grid(...) def deselect_all(): for btn in checkbuttons + checkbuttons1: btn.deselect() deselect_button = tk.Button(ButtonFrame, text='Deselect All', anchor='nw', command=deselect_all) deselect_button.grid(row=3, column=2) RE: Creating a deselect button - dwayne091 - May-18-2024 Thanks it worked perfectly |