The next step, ( left to the reader as an exercise), is to encapsulate the round rectangles in a class.Įdit: how to fill a rounded corners rectangle: Make_round_corners_rect(canvas, *TL, *BR, ratio=.1) That_rect = make_round_corners_rect(canvas, *TL, *BR, ratio=.3) Make_round_corners_rect(canvas, *TL, *BR, ratio=.07) That_rect = make_round_corners_rect(canvas, *TL, *BR, ratio=.4)Ĭemconfig(fragment, outline='blue') Make_round_corners_rect(canvas, *TL, *BR, ratio =. Make_round_corners_rect(canvas, *TL, *BR) Item = canvas.create_line(*blu, *tld, fill='black')Ĭanvas = tk.Canvas(root, width=500, height=500) Item = canvas.create_line(*brl, *blr, fill='black') Item = canvas.create_line(*trd, *bru, fill='black') Item = canvas.create_line(*tlr, *trl, fill='black') All fragments are tagged with their companions' ids, so accessing the entire object is possible with only one fragment id.ĭef make_round_corners_rect(canvas, x0, y0, x1, y1, ratio=0.2, npts=12): The function make_round_corners_rect returns a tuple containing all canvas item ids as fragments of the rectangle entity. The corners radii is expressed as a proportion of the shortest side of the rectangle (0.0 -> 0.5), and can be parametrized. Here is one approach that uses the built in tcl tk primitives canvas.create_line, and canvas.create_arc to build rectangles of various sizes, and proportions with round corners (arc of a circle). So how can I change this code to remove the stretched roundness and keep it a constant radius? When I adapted this code to work with my graphics library, it worked well enough! but when I create a 'stretched-square' (a non-square rectangle), the roundness becomes stretched too: Points.append((ratioMultiplier*y + y)/ratioDividend) Points.append((ratioMultiplier*x + x)/ratioDividend) The more the sharpness, the more these points will be # the more the sub-points will be closer to the vertex. # The sharpness here is just how close the sub-points You need to derive your own widget for this though, from Fl_Box say, as it is not an “out of the box” feature.I came across this interesting question ( How to make a tkinter canvas rectangle with rounded corners?) related to creating rounded rectangles in Tkinter and specifically, this answer by Francisco Gomes (modified a bit): def roundPolygon(x, y, sharpness): Typically, you’d do this by rendering to a (rectangular) offscreen surface, then mask that with a “barn door” (usually only two states, transparent and opaque) alpha channel mask to show the appropriate final shape. You can of course create those effects in fltk, but there are no “default” widgets that will do that. It may be that, if it is a style you need, then some heavier-weight toolkit might be a better fit for that task. It is, I think, very much a “horses for courses” thing, though.Ĭlipping to non-rectilinear bounds is potentially complex in a lot of cases, so does not represent a good fit for the fltk “fast and light” ethos. Just look at the design of Google Groups (or any google product), you'll find a plethora of rounded edges. > It doesn't seem like there's much appetite for rounded edges here, but I think saying that the use cases are too far and few between ignores the fact that rounded frames are both useful and popular tool for designing GUIs. > I'm sure you could find some way to edit the pixel data of the image themselves to get these rounded edges, but that sounds very complicated. As far as I can tell there's no way to clip to rounded edges in FLTK in a way that would (with reasonable effort) create such effects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |