Write a python code to show a white canvas and draw on it with the mouse in black, and…
Jump to turn (6)
- 1Write a python code to show a white canvas and draw on it with the mouse in blac
- 2Do not fade the white background. Fade the black foreground object to a lighter
- 3Fade by 80%, and also fade the existing gray fg objects by the same percentage.
- 4Fade only by a small amount each time, and find gray objects and fade them furth
- 5Fade by a smaller amount, and add another button to save a screenshot of the can
- 6Instead of taking the filename from the user, use the prefix "draw-fade" and tim
- User
Write a python code to show a white canvas and draw on it with the mouse in black, and add a button that will fade the saturation of the current stuff on the canvas so that new drawing would look very dark.
- Assistant
Here's a simple implementation in Python using thetkinterlibrary, which provides a GUI interface for building desktop applications:
────────────────────────────────────────────────────────────────────
pythonCopyimport tkinter as tk
def fade_saturation(): canvas.config(bg="gray50")
root = tk.Tk() root.title("Canvas with fading saturation")
canvas = tk.Canvas(root, bg="white", , width=400) canvas.pack()
button = tk.Button(root, text="Fade Saturation", command=fade_saturation) button.pack()
def draw(event): x, y = event.x, event.y canvas.create_oval(x-5, y-5, x+5, y+5, fill="black")