MCPcopy Create free account
hub / github.com/JamesDevaSingh/Controller-for-disabled / create_rounded_button

Function create_rounded_button

button_screen.py:125–159  ·  view source on GitHub ↗
(widget, radius=15)

Source from the content-addressed store, hash-verified

123
124 # Apply rounded corners using canvas
125 def create_rounded_button(widget, radius=15):
126 # Function to be called when button needs to be drawn
127 def _on_configure(event):
128 # Get the button's dimensions
129 width, height = event.width, event.height
130
131 # Create a rounded rectangle on the canvas
132 canvas.delete("all")
133 canvas.create_rounded_rectangle(0, 0, width, height, radius=radius, fill="#D8BFD8", outline="#9370DB", width=2)
134 canvas.create_text(width/2, height/2, text=text, fill="#4B0082", font=custom_font)
135
136 # Create a canvas that will sit on top of the button
137 canvas = tk.Canvas(frame, highlightthickness=0, bg="#E6E6FA")
138 canvas.place(relwidth=1, relheight=1, in_=button)
139
140 # Add rounded rectangle creation method to canvas
141 tk.Canvas.create_rounded_rectangle = lambda self, x1, y1, x2, y2, radius=25, **kwargs: self.create_polygon(
142 x1+radius, y1,
143 x2-radius, y1,
144 x2, y1+radius,
145 x2, y2-radius,
146 x2-radius, y2,
147 x1+radius, y2,
148 x1, y2-radius,
149 x1, y1+radius,
150 smooth=True, **kwargs
151 )
152
153 # Bind the canvas redraw to configure events (resize)
154 canvas.bind("<Configure>", _on_configure)
155
156 # Bind click events to the canvas that forward to the button
157 canvas.bind("<Button-1>", lambda event: command())
158
159 return canvas
160
161 canvas = create_rounded_button(button)
162

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected