Created
March 7, 2017 13:00
-
-
Save stahnni/3b1effd6e4a43d25a57575bcec2cfbbe to your computer and use it in GitHub Desktop.
use tkinter to move an image across screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Try displaying a photo of yourself on the canvas using tkinter. | |
Make sure it’s a GIF image! Can you make it move across the | |
screen?""" | |
import time | |
from tkinter import * | |
tk = Tk() | |
w = 500 | |
h = 500 | |
canvas = Canvas(tk, width=w, height=h) | |
canvas.pack() | |
my_image = PhotoImage(file='C:\\WinPython-64bit-3.5.3.0Qt5\\notebooks\\stani.gif') | |
my_img = canvas.create_image(0,0, anchor=NW, image=my_image) | |
for x in range(0,60): | |
canvas.move(my_img, 5, 0) | |
tk.update() | |
time.sleep(0.05) | |
for x in range(0,60): | |
canvas.move(my_img, 0, 5) | |
tk.update() | |
time.sleep(0.05) | |
for x in range(0,60): | |
canvas.move(my_img, -5, 0) | |
tk.update() | |
time.sleep(0.05) | |
for x in range(0,60): | |
canvas.move(my_img, 0, -5) | |
tk.update() | |
time.sleep(0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow.... THANK YOU.