I have tried using the following code to draw points that create a line in tkinter:
import tkinter as tk
from time import sleep
def myfunction(event):
x, y = event.x, event.y
x1 = (x+1)
y1 = (y+1)
canvas.create_line(x, y, x1, y1)
sleep(0.5)
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=400)
canvas.pack()
root.bind('d', myfunction)
root.mainloop()
Understandably, the program only draws a point when I press 'd'. I have tried using loops within the myfunction
function like this:
def myfunction(event):
x, y = event.x, event.y
x1 = (x+1)
y1 = (y+1)
for x in range(0,5):
canvas.create_line(x, y, x1, y1)
sleep(0.1)
but this does not work. I have tried many other solutions but none seem to work.
Is there a solution to this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…