2017-02-19 9 views
0

私はpythonでtkinterを使ってプログラムを作っていますが、1秒後に削除するキャンバスオブジェクトが必要ですが、どの関数を使うべきか分かりません。 :tkinterを使って行を削除する方法

def click(event): 
    canvas.create_line(event.x, event.y, coords) 
    canvas.after(1000,canvas.delete) 

canvas.bind('<B1-Motion>',click) 

私はこの行をちょうどそこにとどめています。

答えて

0

キャンバスにアイテムを作成すると、tkinterは一意の識別子を返します。識別子を保存して、canvas.deleteのパラメータとして使用するだけです。

def click(event): 
    canvas_id = canvas.create_line(event.x, event.y, coords) 
    canvas.after(1000, canvas.delete, canvas_id) 
関連する問題