Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a deselect button
#1
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()
Gribouillis write May-18-2024, 07:57 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Creating a deselect button - by dwayne091 - May-18-2024, 07:48 AM
RE: Creating a deselect button - by Gribouillis - May-18-2024, 08:09 AM
RE: Creating a deselect button - by dwayne091 - May-18-2024, 08:41 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020