Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Assistance Assigning values to some check buttons #2583

Open
yoboy1102 opened this issue Sep 19, 2024 · 2 comments
Open

Need Assistance Assigning values to some check buttons #2583

yoboy1102 opened this issue Sep 19, 2024 · 2 comments

Comments

@yoboy1102
Copy link

This isnt completely a custom tkinter problem/help, but I cannot figure out a way to Assign specific values to each of the many checkboxes I have created

  • Python -- 3.12
  • CustomTkinter

import customtkinter as ctk

web = ctk.CTk()
def CBcheck_val(p, q):
    print(p, q)
    #There is much more to do with these Values
eco_buss = ctk.CTkFrame(web,
                           width=185-8, height=320,
                           corner_radius=25,
                           fg_color='white',
                           bg_color='transparent',
                           )
eco_buss.grid(row=0, column=0, padx=4, pady=20)
n, m=4, 6    
let_list = [' A', 'B ', ' C ', 'D ', ' E', ' F ']
var = ctk.IntVar()
eco_rad = []
k,l=0, 0
for i in range(m):
    ff=0
    let_new = let_list[0:n]
    let_new.insert(int(n/2), '    ')
    for j in range(n):
        
        var = ctk.IntVar(eco_buss)  
        ff+=1.4
        
        #print(ff, int(ff), int(ff-1))
        radd = ctk.CTkCheckBox(eco_buss,
                                corner_radius=8, fg_color='#3DCCB2', text=None,
                                variable=var, 
                                onvalue=None,
                                border_color='#3DCCB2', checkbox_height=43, checkbox_width=33,
                                height=20, width=0, command=lambda: CBcheck_val(i, j))
        radd.grid(row=i+1, column=int(ff-1), padx=3, pady=10)
        
web.mainloop()

Each Time Tick a checkbox it gives the same values of i and j which are the last updated values of them ofc, Now how do I get specific values for each values bakc, here I am just printing them but I need them for much more, How can I assign those specific values each button has,
Thanks

@ghost
Copy link

ghost commented Sep 19, 2024

Here is the fixed code:

import customtkinter as ctk

web = ctk.CTk()

def CBcheck_val(p, q):
    print(p, q)
    # There is much more to do with these values

eco_buss = ctk.CTkFrame(web,
                           width=185-8, height=320,
                           corner_radius=25,
                           fg_color='white',
                           bg_color='transparent',
                           )
eco_buss.grid(row=0, column=0, padx=4, pady=20)

n, m = 4, 6    
let_list = [' A', 'B ', ' C ', 'D ', ' E', ' F ']
var = ctk.IntVar()
eco_rad = []
k, l = 0, 0

for i in range(m):
    ff = 0
    let_new = let_list[0:n]
    let_new.insert(int(n/2), '    ')
    
    for j in range(n):
        var = ctk.IntVar(eco_buss)
        ff += 1.4
        
        radd = ctk.CTkCheckBox(eco_buss,
                               corner_radius=8, fg_color='#3DCCB2', text=None,
                               variable=var, 
                               onvalue=1,  
                               border_color='#3DCCB2', checkbox_height=43, checkbox_width=33,
                               height=20, width=0, command=lambda i=i, j=j: CBcheck_val(i, j))
        radd.grid(row=i+1, column=int(ff-1), padx=3, pady=10)

web.mainloop()

@yoboy1102
Copy link
Author

I cannot thank you enough brother(/sister), this is legit so simple yet mindbreaking to me, Thanks so much, this will help in a lot of my gui designs, feel dumb to not thought of this, TY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant