Skip to content

Commit 5ecb5a4

Browse files
committed
feat: add color change functionality to Edge and Node classes
1 parent 3df0f71 commit 5ecb5a4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Graph/edge.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@ def __init__(self, parent: 'FrameGraph', first_node_number: int, second_node_num
3737
self.place(x=min(x1, x2), y=min(y1, y2))
3838
line_x1, line_y1 = x1 - min(x1, x2), y1 - min(y1, y2)
3939
line_x2, line_y2 = x2 - min(x1, x2), y2 - min(y1, y2)
40-
self.create_line(line_x1, line_y1, line_x2,
41-
line_y2, fill="black", width=2)
40+
self.oval_id = self.create_line(line_x1, line_y1, line_x2,
41+
line_y2, fill="black", width=2)
42+
43+
def change_color(self, color: str):
44+
self.itemconfig(self.oval_id, fill=color)

src/Graph/node.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def __init__(self, parent: 'FrameGraph', number: int, x: float, y: float):
2525
self.y = y
2626
self.number = number
2727
self.configure(bg="white")
28-
self.create_oval(0, 0, 60, 60, fill="blue", outline="#F8F9FA")
28+
self.oval_id: int = self.create_oval(
29+
0, 0, 60, 60, fill="blue", outline="#F8F9FA")
2930
self.create_text(30, 30, text=str(number), font=("Arial", 20, "bold"))
3031
self.pack()
3132
self.place(x=x - 30, y=y - 30)
@@ -37,3 +38,11 @@ def get_center(self) -> tuple[float, float]:
3738
tuple[float,float]: x_center_pos and y_center_pos
3839
"""
3940
return self.x, self.y
41+
42+
def change_color(self, color: str):
43+
"""Change the color of the node
44+
45+
Args:
46+
color (str): The new color for the node
47+
"""
48+
self.itemconfig(self.oval_id, fill=color)

0 commit comments

Comments
 (0)