This question already has an answer here:
def check_letter(self):
if self.entered_letter.text().upper() or self.entered_letter.text().lower() in self.word:
self.guessed_letters += self.entered_letter.text().upper()
self.guessed_letters += self.entered_letter.text().lower()
self.correct.setVisible(True)
QApplication.processEvents()
sleep(0.2)
self.correct.setVisible(False)
QApplication.processEvents()
else:
self.number += 1
self.image.setPixmap(QPixmap('hangman_{}.png'.format(self.number)).scaled(100, 200, Qt.KeepAspectRatio, Qt.FastTransformation))
self.incorrect.setVisible(True)
QApplication.processEvents()
sleep(0.2)
self.incorrect.setVisible(False)
QApplication.processEvents()
blank_word = ''
for i in self.word:
if i in self.guessed_letters:
blank_word += i
else:
blank_word += '_ '
blank_word.rstrip()
self.blank_word_label.setText(blank_word)
self.entered_letter.setText('')
This is the hangman game project I'm working on using PyQt5 with Python 3.5 on my Windows 7 32-bit machine. The problem is that my else-block does not execute in this function no matter what I do, but the if-block seems to always execute no matter what or at least the last 5 lines in the if-block do.
Full Code: http://ift.tt/2fs3Ini
Aucun commentaire:
Enregistrer un commentaire