Skip to content

add empty_string_replacement arg #122

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions CTkTable/ctktable.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
hover: bool = False,
justify: str = "center",
wraplength: int = 1000,
empty_string_replacement: str = " ", # isghe 20250312_1637: space for backwards compatibility
**kwargs):

super().__init__(master, fg_color="transparent")
Expand Down Expand Up @@ -90,6 +91,7 @@ def __init__(

self.frame = {}
self.corner_buttons = {}
self.empty_string_replacement = empty_string_replacement
self.draw_table(**kwargs)

def draw_table(self, **kwargs):
Expand Down Expand Up @@ -166,12 +168,12 @@ def draw_table(self, **kwargs):
value = self.values[i][j]
else:
value = self.values[j][i]
except IndexError: value = " "
except IndexError: value = self.empty_string_replacement
else:
value = " "
value = self.empty_string_replacement

if value=="":
value = " "
value = self.empty_string_replacement

if (i,j) in self.data.keys():
if self.data[i,j]["args"]:
Expand Down Expand Up @@ -224,7 +226,7 @@ def draw_table(self, **kwargs):
corner_radius=0,
**args)
if value is None:
value = " "
value = self.empty_string_replacement
self.frame[i,j].insert(0, str(value))
self.frame[i,j].bind("<Key>", lambda e, row=i, column=j, data=self.data: self.after(100, lambda: self.manipulate_data(row, column)))
self.frame[i,j].grid(column=j, row=i, padx=padx, pady=pady, sticky="nsew")
Expand All @@ -251,7 +253,7 @@ def draw_table(self, **kwargs):
args.update({"anchor": anchor})
del args["justify"]
if value is None:
value = " "
value = self.empty_string_replacement
self.frame[i,j] = customtkinter.CTkButton(self.inside_frame, background_corner_colors=corners,
font=self.font,
corner_radius=corner_radius,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ _here, **args** means ctkbutton parameters which can also be passed_
| hover_color | enable hover effect on the cells |
| wraplength | set the width of cell text |
| justify | anchor the position of the cell text |
| empty_string_replacement | replace None or Empty string with empty_string_replacement (default is a space " ")
| **command** | specify a command when a table cell is pressed, [returns row, column, value] |
| **other button parameters* | all other ctk button parameters can be passed |

Expand Down