Skip to content

Commit 60dd830

Browse files
Python Tkinter Drag and Drop Images The Mouse start
1 parent 6aa2219 commit 60dd830

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Python Tkinter Drag and Drop Images The Mouse
2+
# Python Tkinter Arrastrar y soltar imágenes con el mouse
3+
4+
from tkinter import *
5+
6+
root = Tk()
7+
root.title('Python Tkinter Drag and Drop Images The Mouse')
8+
root.iconbitmap('Python Tkinter Drag and Drop Images The Mouse/icons/fun.ico')
9+
root.geometry("800x600")
10+
11+
w = 600
12+
h = 400
13+
x = w/2
14+
y = h/2
15+
16+
my_canvas = Canvas(root, width=w, height=h, bg="white")
17+
my_canvas.pack(pady=10)
18+
19+
# my_circle = my_canvas.create_oval(x, y, x+10, y+10)
20+
# Add image to Canvas
21+
img = PhotoImage(file="Python Tkinter Drag and Drop Images The Mouse/images/eddy.png")
22+
my_image = my_canvas.create_image(260,125, anchor=NW, image=img)
23+
24+
def left(event):
25+
x = -10
26+
y= 0
27+
my_canvas.move(my_image, x, y)
28+
29+
def right(event):
30+
x = 10
31+
y= 0
32+
my_canvas.move(my_image , x, y)
33+
34+
def up(event):
35+
x =0
36+
y= -10
37+
my_canvas.move(my_image , x, y)
38+
39+
def down(event):
40+
x =0
41+
y= 10
42+
my_canvas.move(my_image , x, y)
43+
44+
root.bind("<Left>", left)
45+
root.bind("<Right>", right)
46+
root.bind("<Up>", up)
47+
root.bind("<Down>", down)
48+
49+
root.mainloop()
50+
Binary file not shown.
Loading

Python Tkinter how to Move Images on Canvas/howMoveImagesCanvas.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,5 @@ def down(event):
4646
root.bind("<Up>", up)
4747
root.bind("<Down>", down)
4848

49-
5049
root.mainloop()
5150

0 commit comments

Comments
 (0)