When I programmed Lesson 7-3 in the textbook I dealt with in the class, I thought that I could draw a line if I did this drawing continuously, but I made it into a shape while investigating.
――In the textbook, you programmed to draw a circle by clicking, but this time it is drawn all the time while the mouse button is pressed. ――To draw a line, it becomes unnatural if the drawn circle is large, so I made it possible to draw a more natural line by drawing as small a circle as possible.
I will introduce the code that was actually programmed.
press = True
First, here we define clicking the mouse button.
press = False
Next, define that you release the mouse button.
x = event.x
y = event.y
canvas.create_oval(x - 2, y - 2, x + 2, y + 2, fill = "white", width=0)
And finally, we define drawing a circle when the mouse is moving and the button is held down.
In order to draw a circle continuously, it is necessary not only to turn the button on and off, but also to separate the cases of ** 3 patterns that are ON and the mouse is moving **. At first, I was thinking of moving the mouse while pressing the button and releasing the button, but I didn't know what to do. So, when I referred to the site, I was impressed when I saw that the press was set to true false by turning the button on and off.
I tried to make it look like a blackboard!
If you move the mouse quickly, the lines will not be clean. It seems that this is a processing problem of the personal computer. It may be possible to improve if the method is not a method of drawing dots continuously.
Once you make a mistake, you cannot erase it. Since it is decided whether to draw a dot by pressing or not pressing the mouse button, there is not enough definition to perform the action of erasing the dot. It may be possible to erase the case if something can be done before pressing the mouse button.
It was my first time to come into contact with programming, so there were some difficult parts, but I enjoyed working on it. I'm interested, so I'll try to work on it voluntarily.
Create a GUI app using Tkinter in python [https://daeudaeu.com/programming/python/tkinter/python_tkinter/]
The easiest Python introductory class by Fumitaka Osawa