Skip to content

Commit

Permalink
add vertical segmented button tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Nelson committed Mar 26, 2024
1 parent 7221d27 commit a175385
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
21 changes: 16 additions & 5 deletions customtkinter/windows/widgets/ctk_segmented_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,27 @@ def _configure_button_corners_for_index(self, index: int):

elif index == 0:
if self._background_corner_colors is None:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._bg_color, self._sb_fg_color, self._sb_fg_color, self._bg_color))
if self._vertical:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._bg_color, self._bg_color, self._sb_fg_color, self._sb_fg_color))
else:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._bg_color, self._sb_fg_color, self._sb_fg_color, self._bg_color))
else:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._background_corner_colors[0], self._sb_fg_color, self._sb_fg_color, self._background_corner_colors[3]))
if self._vertical:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._background_corner_colors[0], self._background_corner_colors[1], self._sb_fg_color, self._sb_fg_color))
else:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._background_corner_colors[0], self._sb_fg_color, self._sb_fg_color, self._background_corner_colors[3]))

elif index == len(self._value_list) - 1:
if self._background_corner_colors is None:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._sb_fg_color, self._bg_color, self._bg_color, self._sb_fg_color))
if self._vertical:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._sb_fg_color, self._sb_fg_color, self._bg_color, self._bg_color))
else:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._sb_fg_color, self._bg_color, self._bg_color, self._sb_fg_color))
else:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._sb_fg_color, self._background_corner_colors[1], self._background_corner_colors[2], self._sb_fg_color))
if self._vertical:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._sb_fg_color, self._sb_fg_color, self._background_corner_colors[2], self._background_corner_colors[3]))
else:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._sb_fg_color, self._background_corner_colors[1], self._background_corner_colors[2], self._sb_fg_color))

else:
self._buttons_dict[self._value_list[index]].configure(background_corner_colors=(self._sb_fg_color, self._sb_fg_color, self._sb_fg_color, self._sb_fg_color))
Expand Down Expand Up @@ -181,7 +193,6 @@ def _check_unique_values(values: List[str]):

def _create_button_grid(self):
number_of_columns, number_of_rows = self.grid_size()
print(number_of_columns, number_of_rows)
if self._vertical:
# remove minsize from every grid cell in the first column
for n in range(number_of_rows):
Expand Down
50 changes: 29 additions & 21 deletions test/manual_integration_tests/test_segmented_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,35 @@
label_seg_5 = customtkinter.CTkLabel(app, textvariable=seg_5_var)
label_seg_5.pack(padx=20, pady=20)

seg_6_var = customtkinter.StringVar(value="kfasjkfdklaj")
seg_6 = customtkinter.CTkSegmentedButton(app, width=300)
seg_6.pack(padx=20, pady=20)
entry_6 = customtkinter.CTkEntry(app)
entry_6.pack(padx=20, pady=(0, 20))
button_6 = customtkinter.CTkButton(app, text="set", command=lambda: seg_6.set(entry_6.get()))
button_6.pack(padx=20, pady=(0, 20))
button_6 = customtkinter.CTkButton(app, text="insert value", command=lambda: seg_6.insert(0, entry_6.get()))
button_6.pack(padx=20, pady=(0, 20))
label_6 = customtkinter.CTkLabel(app, textvariable=seg_6_var)
label_6.pack(padx=20, pady=(0, 20))

seg_6.configure(height=50, variable=seg_6_var)
seg_6.delete("CTkSegmentedButton")

seg_7 = customtkinter.CTkSegmentedButton(app, values=["disabled seg button", "2", "3"])
seg_7.pack(padx=20, pady=20)
seg_7.configure(state="disabled")
seg_7.set("2")

seg_7.configure(height=40, width=400,
seg_6 = customtkinter.CTkSegmentedButton(app, corner_radius=20, values=["value 1", "value 2", "value 3"], background_corner_colors=["red", "orange", "green", "blue"], vertical=True)
seg_6.set("value 2")
seg_6.pack(side="left", padx=40)

seg_7 = customtkinter.CTkSegmentedButton(app, corner_radius=40, values=["value 4", "value 5", "value 6"], vertical=True)
seg_7.set("value 6")
seg_7.pack(side="left")

seg_8_var = customtkinter.StringVar(value="kfasjkfdklaj")
seg_8 = customtkinter.CTkSegmentedButton(app, width=300)
seg_8.pack(padx=20, pady=20)
entry_8 = customtkinter.CTkEntry(app)
entry_8.pack(padx=20, pady=(0, 20))
button_8 = customtkinter.CTkButton(app, text="set", command=lambda: seg_8.set(entry_8.get()))
button_8.pack(padx=20, pady=(0, 20))
button_8 = customtkinter.CTkButton(app, text="insert value", command=lambda: seg_8.insert(0, entry_8.get()))
button_8.pack(padx=20, pady=(0, 20))
label_8 = customtkinter.CTkLabel(app, textvariable=seg_8_var)
label_8.pack(padx=20, pady=(0, 20))

seg_8.configure(height=50, variable=seg_8_var)
seg_8.delete("CTkSegmentedButton")

seg_9 = customtkinter.CTkSegmentedButton(app, values=["disabled seg button", "2", "3"])
seg_9.pack(padx=20, pady=20)
seg_9.configure(state="disabled")
seg_9.set("2")

seg_9.configure(height=40, width=400,
dynamic_resizing=False, font=("Times", -20))

app.mainloop()

0 comments on commit a175385

Please sign in to comment.