Skip to content

Commit 20887db

Browse files
committed
refresh before popup
1 parent b181e5f commit 20887db

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

minesweeper.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
from tkinter import *
55
from tkinter import messagebox as tkMessageBox
6+
from collections import deque
67
import random
78
import platform
8-
from collections import deque
9+
import time
910

1011
STATE_DEFAULT = 0
1112
STATE_CLICKED = 1
@@ -120,13 +121,6 @@ def rclicked_wrapper(self, x, y):
120121

121122
def lclicked(self, button_data):
122123
if button_data["isMine"] == True:
123-
# show all mines and check for flags
124-
for x in range(0, 10):
125-
for y in range (0, 10):
126-
if self.buttons[x][y]["isMine"] == False and self.buttons[x][y]["state"] == STATE_FLAGGED:
127-
self.buttons[x][y]["widget"].config(image = self.tiles["wrong"])
128-
if self.buttons[x][y]["isMine"] == True and self.buttons[x][y]["state"] != STATE_FLAGGED:
129-
self.buttons[x][y]["widget"].config(image = self.tiles["mine"])
130124
# end game
131125
self.gameover()
132126
else:
@@ -197,13 +191,21 @@ def clear_empty_tiles(self, id):
197191
self.check_tile(source_x+1, source_y+1, queue) #bottom left
198192

199193
def gameover(self):
200-
tkMessageBox.showinfo("Game Over", "You Lose!")
194+
for x in range(0, 10):
195+
for y in range (0, 10):
196+
if self.buttons[x][y]["isMine"] == False and self.buttons[x][y]["state"] == STATE_FLAGGED:
197+
self.buttons[x][y]["widget"].config(image = self.tiles["wrong"])
198+
if self.buttons[x][y]["isMine"] == True and self.buttons[x][y]["state"] != STATE_FLAGGED:
199+
self.buttons[x][y]["widget"].config(image = self.tiles["mine"])
201200
global root
201+
root.update()
202+
tkMessageBox.showinfo("Game Over", "You Lose!")
202203
root.destroy()
203204

204205
def victory(self):
205-
tkMessageBox.showinfo("Game Over", "You Win!")
206206
global root
207+
root.update()
208+
tkMessageBox.showinfo("Game Over", "You Win!")
207209
root.destroy()
208210

209211
def update_flags(self):

0 commit comments

Comments
 (0)