From 5f65508f156a1c0cbf72d79a455bf0be53dde337 Mon Sep 17 00:00:00 2001 From: DolphyWind Date: Thu, 29 Sep 2022 18:21:17 +0300 Subject: [PATCH] Fixed a bug Fixed the bug that crashes program when you clicked "Surf Words" without a word data. --- main.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.py b/main.py index b988e43..90255de 100644 --- a/main.py +++ b/main.py @@ -49,6 +49,11 @@ def switchMenu(self, menu: Menu, wordData: word.Word = None): if menu == Menu.PLAY_GAME: return + if menu == Menu.SURF_WORDS: + if len(self.wordData) == 0: + QtWidgets.QMessageBox.warning(self, 'Error!', 'You Have to add some words to your dictionary!', QtWidgets.QMessageBox.Ok) + return + if menu == self.previousMenu: self.menuList.pop(-1) @@ -586,6 +591,8 @@ def changeWord(index, step): def getRandomWord(): new_word = word.Word() keys_list = list(self.wordData.keys()) + if len(keys_list) <= 1: + return randomWord = random.choice(keys_list) while randomWord == currentWord.word: randomWord = random.choice(keys_list)