The idea is if i had an image in the background i can still see the image with the circle on top. Resize text layers: Resizing text layers. Tk.Button(canvas, text="Text", command=text).pack(pady=10) Fill with: you can fill resized layers with Transparency (default), Background color, Foreground color, White, Pattern. Tk.Button(canvas, text="Rectangle", command=rectangle).pack() strokeRect (x, y, width, height) Draws a rectangular outline. To clear to a specific color, use the fillRect. I am working on a website and I try to get rectangles on a HTML5 canvas with javascript. Tk.Button(canvas, text="Circle", command=circle).pack(pady=10) There are three functions that draw rectangles on the canvas: fillRect (x, y, width, height) Draws a filled rectangle. The clearRect method clears the canvas to transparent black (that is, each pixels RGBA value is equal to zero). import tkinter as tkĬanvas.create_oval(x, y, x + diameter, y + diameter)Ĭanvas.create_rectangle(x, y, x + randint(10, 100), y + randint(10, 100))Ĭanvas.create_text(x, y, text=f"x=") Note: See also the chapter Applying styles and color in the Canvas Tutorial. Window.mainloop()For drawing on a complex background my suggestion is make a big canvas and draw everything on the canvas, including things like buttons and labels if need be. The CanvasRenderingContext2D.globalAlpha property of the Canvas 2D API specifies the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas. Tk.Button(window, text="Circle", command=circle).pack() Window.title("Drawing Shapes on Button Press")Ĭ = tk.Canvas(window, width=100, height=100, background=window, bd=0, highlightthickness=0) That will not solve the problem of drawing a canvas on a complex background, but it will work for your example. You could inherit the window's background. The CanvasRenderingContext2D. Any text inside the
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |