pythongui选择背景色_在python GUI中更改按钮颜色

import sys

from tkinter import *

def run_GUI():

# create the window

root = Tk()

frame = Frame(root)

frame.pack()

#modify root window

root.title("Simple GUI")

root.geometry("700x300") # w x h

def SP2T(): # Edit occurs here where I forgot to pit that the button was created in a called funtction

#Creates Row

frameSP2T = Frame(root)

frameSP2T.pack(side = TOP)

#Creating Buttons First Row

button1 = Button(frameSP2T, padx=13, pady = 6, bd=4, text="SW02",fg = "black", command = SW02)

button1.pack(side = LEFT)

def SW02():

print("SW02 is on")

button1["fg"] = "green"

#Sets up initial boot screen

#Creates Row

topframe = Frame(root)

topframe.pack(side = TOP)

#Creating Buttons First Row

buttonA = Button(topframe, padx=13, pady = 6, bd=4, text="SP2T",fg = "black", command = SP2T)

buttonA.pack(side = LEFT)

buttonB = Button(topframe, padx=12, pady = 6, bd=4, text="SP4T",fg = "black")

buttonB.pack(side = LEFT)

buttonC = Button(topframe, padx=12, pady = 6, bd=4, text="SP12T",fg = "black")

buttonC.pack(side = LEFT)

buttonD = Button(topframe, padx=12, pady = 6, bd=4, text="QUIT", fg="red",command=frame.quit)

buttonD.pack(side = LEFT)

#Kick off event loop

root.mainloop()

return

run_GUI()

我得到了一个错误:

^{pr2}$

更新的版本,希望能显示整个画面

这个程序还有更多内容,所以它说第60行,但这是问题所在。我在试着改变按钮按下时的颜色。在