I’m writing a blackjack-program where the user decides 1 out of 4 actions using buttons on the screen. Each button sets the action-variable to another number, based on it’s state the program continues appropriately.
As I understood, Tk.wait_variable(action) is supposed to make Tk wait until the variable changes, or in my case until one of the buttons is clicked. I can’t get it working properly though and keep receiving the following error: **_tkinter.TclError: wrong # args: should be “tkwait variable|visibility|window name”
I couldn’t find any resources to explain what this error-code means and what I’m supposed to change. The GUI and the buttons work properly and change the value of self.action.
Here the (abbreviated) code. The forth function “def play_hand” is relevant.
class CardsGui():
def __init__(self, game):
self.window = Tk()
self.blackjack()
self.window.mainloop()
def set_action(self, action):
print(action)
self.action = action
def blackjack(self):
self.action_buttons = []
button_split = Button(text="Stand", command=lambda: self.set_action(3), width=10)
button_split.grid(column=1, row=9, padx=20, pady=20)
self.action_buttons.append(button_split)
hand = self.bj_play_hand(player_number, player)
def play_hand(self, player_number, hand, AI=False):
self.display_hand(player_number, hand)
self.action = None
self.window.wait_variable(self.action)
if self.action == 0:
print("Stand")
elif self.action == 1:
print("Hit")
elif self.action == 2:
print("Double")
elif self.action == 3:
print("Split")