Akascape / CTkTable

Customtkinter Table widget (extension/add-on)
MIT License
265 stars 15 forks source link

Help showing a value when clicked on. #38

Closed broshv closed 1 year ago

broshv commented 1 year ago

Hello, I'm attempting to make an password manager using CustomTkinter and CTkTable. I made a successful selector for the table, but now I want to make it so when you select a row, the "password" column will go from showing "****" to the actual password (password column is the 3rd column, 2nd in python syntax). How would I go about doing this?

My code so far:

row_nums = []
row_vals = []

def show(cell):
    if cell["row"] not in row_nums: # if the row im selecting isnt selected
        if cell["row"] != 0: # make sure the row isnt the first row (first row is being used for labels of the columns)
            if len(row_vals) > 0: # if there is a row that is selected already, deselect it and remove it
                # here is where i want the 3rd columns text of the old row to return to "****" since it is being deselected
                table.deselect_row(row_nums[0])
                row_nums.remove(row_nums[0])
                row_vals.remove(row_vals[0])

            # here is where i want the 3rd columns text of the new row to become the passwords text
            table.select_row(cell["row"])
            row_nums.append(cell["row"])
            row_vals.append(table.get()[cell["row"]])
    else: # if the row im selecting IS already selected, deselect it
        table.deselect_row(row_nums[0])
        row_nums.remove(row_nums[0])
        row_vals.remove(row_vals[0])

table = CTkTable(scrollframe,row=len(values)+100,column=3,values=values,command=show)
table.grid(column=0,row=0)
Akascape commented 1 year ago

@broshv Please refer this example:

import customtkinter
from CTkTable import *

root = customtkinter.CTk()

def show(cell):
    table.edit_column(1, value="****")
    for i in range(len(value)):
        table.deselect_row(i)
    password = value[cell["row"]][1]
    table.insert(cell["row"], 1, value=password)
    table.select_row(cell["row"])

value = [["A", "password1"], ["B", "password2"], ["C", "password3"], ["D", "password4"], ["E", "password5"]]

table = CTkTable(master=root, row=5, column=2, values=value, command=show)
table.pack(expand=True, fill="both", padx=20, pady=20)
table.edit_column(1, text="****")

root.mainloop()
broshv commented 1 year ago

I tried your method out and it works, the only problem is that in my "value" table, the first and last values are both ["Name","Email","Password"] (to show the user the names of the columns), and this method also makes the "Password" label become "****", is there any way to stop this from happening?

broshv commented 1 year ago

Ah, nevermind! I used the table.insert method to change those values. Thank you!