I need to pass in 2 more parameters for a function but b - which can only be b1, b2 or b3 - is behind a function but it is called inside of a lambda so when I try and make a new variable - pb1 - it doesn't work.
def b1_click(b):
global p1
p1 = p1.join(b["text"])
b4.config(state=ACTIVE)
b5.config(state=ACTIVE)
b6.config(state=ACTIVE)
b1.config(state=DISABLED)
b2.config(state=DISABLED)
b3.config(state=DISABLED)
return b
def b2_click(b):
global p2
p2 = p2.join(b["text"])
b4.config(state=DISABLED)
b5.config(state=DISABLED)
b6.config(state=DISABLED)
def checkwin(b, bb):
possibilities = [{"Rock", "Scissors"}, {"Scissors", "Paper"}, {"Paper", "Rock"}]
for possibility in possibilities:
checkwinpos(*possibility, b, bb)
def checkwinpos(win, lose, b, bb):
if b["text"] == win and bb["text"] == lose:
b.config(bg="Green")
bb.config(bg="Red")
elif bb["text"] == win and b["text"] == lose:
bb.config(bg="Green")
b.config("Red")
else:
messagebox.showinfo("Jensen The Great's Rock Paper Scissors", "You both picked the same thing")
root = Tk()
root.title("Jensen The Great's Rock Paper Scissors")
root.geometry("1200x710")
b1 = Button(root, text = "Rock", height = 3, width = 6, bg="SystemButtonFace", command=lambda: [pb1 = b1_click(b1)])
b2 = Button(root, text = "Paper", height = 3, width = 6, bg="SystemButtonFace", command=lambda: [pb1 = b1_click(b2)])
b3 = Button(root, text = "Scissors", height = 3, width = 6, bg="SystemButtonFace", command=lambda: [pb1 = b1_click(b3)])
b4 = Button(root, text = "Rock", height = 3, width = 6, bg="SystemButtonFace", command=lambda: [b2_click(b4), checkwin(pb1, b4)])
b5 = Button(root, text = "Paper", height = 3, width = 6, bg="SystemButtonFace", command=lambda: [b2_click(b5), checkwin(pb1, b5)])
b6 = Button(root, text = "Scissors", height = 3, width = 6, bg="SystemButtonFace", command=lambda: [b2_click(b6), checkwin(pb1, b6)])
b4.config(state=DISABLED)
b5.config(state=DISABLED)
b6.config(state=DISABLED)
I was expecting it to work and the button which was pressed - pb1 - to be passed into checkwin and then passed into checkwinpos but it didn't work. The error message is here:
b1 = Button(root, text = "Rock", height = 3, width = 6, bg="SystemButtonFace", command=lambda: [pb1 = b1_click(b1)])
^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?