我正在寫一個簡單的程序,用於拉出圖像(BackgroundFinal.png)並將其顯示在窗口中。我希望能夠按下窗口上的按鈕將圖片向下移動22個像素。除按鈕之外的所有東西都不起作用。更改Tkinter窗口中標籤的位置
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位置。我非常感謝任何幫助,對於我可怕的公約感到遺憾。提前致謝!