On 8/30/2014 11:54 AM, theteacher.i...@gmail.com wrote:
I've started to learn to use tkinter but can't seem to rotate images.

Here is a Python 3.4 program to illustrate the problem.
> Anyone spot why the for loop doesn't seem to want to display
> a sucssession of images please? Thanks.

import sys
from tkinter import *
import random
from time import sleep

myGui = Tk()
myGui.geometry("1000x800+400+100")
myGui.title("The Random Machine")

monsters = ["py01.gif", "py02.gif", "py03.gif", "py04.gif", "py05.gif", "py06.gif", 
"py07.gif", "py08.gif",
             "py09.gif", "py10.gif", "py11.gif", "py12.gif", "py13.gif", "py14.gif", 
"py15.gif", "py16.gif",
             "py17.gif", "py18.gif", "py19.gif", "py20.gif",]


#Main canvas
canvas1 = Canvas(myGui, width=1000, height=800, bg="white")
canvas1.place(x=0,y=0)


#button
myButton1=Button(canvas1, text='OK', justify = LEFT)

for i in range(10):
    myImage = PhotoImage(file="MonsterImages/Converted/" + 
random.choice(monsters))
    myButton1.config(image=myImage, width="100", height="200")
    myButton1.place(x=500,y=300)
    sleep(0.2)

myGui.mainloop()

I tried a simplified version of this in the Idle shell. Idle displays call tips if you pause after typing '('. Unlike .pack and .grid, .place apparently does not automatically put the widget in its master. At least this is true when placing in a canvas. You need an 'in_' argument (the '_' is needed to not be the keyword 'in'). Try

canvas1.pack() #don't use place unless really needed.
...
myButton1.place(in_=canvas1, x=500, y=300)

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to