画像 (BackgroundFinal.png) を取得してウィンドウに表示する簡単なプログラムを作成しています。ウィンドウのボタンを押して、画像を 22 ピクセル下に移動できるようにしたいと考えています。ボタンが何もしないことを除いて、すべてが機能します。
import Tkinter
import Image, ImageTk
from Tkinter import Button
a = 0 #sets inital global 'a' and 'b' values
b = 0
def movedown(): #changes global 'b' value (adding 22)
globals()[b] = 22
return
def window(): #creates a window
window = Tkinter.Tk();
window.geometry('704x528+100+100');
image = Image.open('BackgroundFinal.png'); #gets image (also changes image size)
image = image.resize((704, 528));
imageFinal = ImageTk.PhotoImage(image);
label = Tkinter.Label(window, image = imageFinal); #creates label for image on window
label.pack();
label.place(x = a, y = b); #sets location of label/image using variables 'a' and 'b'
buttonup = Button(window, text = 'down', width = 5, command = movedown()); #creates button which is runs movedown()
buttonup.pack(side='bottom', padx = 5, pady = 5);
window.mainloop();
window()
私が間違っていなければ、ボタンはグローバルな 'b' 値を変更する必要があるため、ラベルの y 位置が変更されます。私のひどい慣習で申し訳ありません。前もって感謝します!