我正在编写一个简单的程序来提取图像(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 位置。我真的很感激任何帮助,对不起我的糟糕的约定。提前致谢!