0

The window doesn't update before the messagebox however the update function (printBoard()) is called before the messagebox.

I have a problem with a tic tac to script against a bot, when there is a winner or a tie game the program shows that to the user using a messagebox, but in my code I call the function printBoard(board) and this updates the window for the game. And after that I call the messagebox.showinfo but as soon as the messagebox shows up the board has not been updated.

(the problem is in the function checkWinner(board))

def printBoard(board):
    bbuttons = [[0,0,0],[0,0,0],[0,0,0]]
    for y in range(0,3):
        for x in range(0,3):
            bbuttons[y][x] = Button(text=board[y][x], font= ('Arial',50))
            bbuttons[y][x].grid(row=y, column=x)
            bbuttons[y][x].config(height=1, width=3)

    return

if checkWinner(board) == 'X':
                o = printBoard(board)
                messagebox.showinfo("WON!", "YOU WON!")
                board = [[' ',' ',' '],[' ',' ',' '],[' ',' ',' ']]
                root.destroy()
                start()

Output:

[['X', 'X', 'O'], ['O', 'X', 'X'], ['X', 'O', 'O']]

I want the board to have been updated so that you can see for example three x's in a row. (now it doesn't it just shows the messagebox when you click the last tile)

UPDATE: Now I'm home and ran the script on my Windows Pc and it works without the problem. It seems to be Mac specifically (I tested it on another mac also).

Cassis
  • 27
  • 1
  • 6
  • please supply a minimal working code that we can test it and reproduce the error – Mahmoud Elshahat Apr 21 '19 at 17:30
  • try `root.update()` before `messagebox`. – furas Apr 21 '19 at 18:25
  • @furas It didn't solve the issue. But thank you anyways, because I learned something new. – Cassis Apr 21 '19 at 19:32
  • It's a **MessageBox** - not a "massagebox" ..... – marc_s Apr 22 '19 at 08:06
  • it seems like the updating window doesn't complete and the message box interrupts it. By putting a delay to show the messagebox should solve the issue . – Saad Apr 22 '19 at 12:37
  • @Saad time.sleep() doesn't work, one of the first things I tried. – Cassis Apr 23 '19 at 08:23
  • You can't use `sleep()`, use [`after()`](https://stackoverflow.com/questions/25753632/tkinter-how-to-use-after-method). Also we can test your code but can you make and provide a small example which has the same problem? – Saad Apr 23 '19 at 08:37

0 Answers0