May-18-2024, 07:48 AM
(This post was last modified: May-18-2024, 07:57 AM by Gribouillis.)
Am trying to create a deselect button to deselect the checkbuttons all at once any ideas on how to do
It?
My code
It?
My code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
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.
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.