这只是按钮数组的初始代码,它们相互影响。我无法理解为什么我不断收到这个定义错误!
from tkinter import *
import tkinter.messagebox
from tkinter import ttk
def changeImage(Num):
global buttonOn
global buttonOff
if Num == 1:
if button1(image) == buttonOn:
button1.config(image=buttonOff)
else:
button1.config(image=buttonOn)
root = Tk()
root.geometry('155x190')
root.title("Tile Turner")
buttonOn = PhotoImage(file="buttonPic.gif")
buttonOff = PhotoImage(file="buttonPic2.gif")
button1 = Button(image=buttonOn, width=20, height=20, command=changeImage(1))
buttonQuit = Button(text="Quit", width=10, height=0, command=root.destroy)
app.grid(column=0, row=0)
button1.grid(column=2, row = 3)
buttonQuit.grid(column=3, row = 10, columnspan = 4)
root.mainloop()
我的定义错误在 button1 中:
Traceback (most recent call last):
File "C:/Users/Jimmy/Desktop/COS 2013/Game1/small", line 23, in <module>
button1 = Button(image=buttonOn, width=20, height=20, command=changeImage(1))
File "C:/Users/Jimmy/Desktop/COS 2013/Game1/small", line 10, in changeImage
if button1(image) == buttonOn:
NameError: global name 'button1' is not defined
任何帮助将不胜感激!