本文整理汇总了Python中PyQt5.QtWidgets.QLCDNumber.setMinimumSize方法的典型用法代码示例。如果您正苦于以下问题:Python QLCDNumber.setMinimumSize方法的具体用法?Python QLCDNumber.setMinimumSize怎么用?Python QLCDNumber.setMinimumSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QLCDNumber
的用法示例。
在下文中一共展示了QLCDNumber.setMinimumSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SinglePlayerGame
# 需要导入模块: from PyQt5.QtWidgets import QLCDNumber [as 别名]
# 或者: from PyQt5.QtWidgets.QLCDNumber import setMinimumSize [as 别名]
class SinglePlayerGame(QWidget):
def __init__(self, difficulty=1, numberOfGames=1):
super(SinglePlayerGame, self).__init__()
self.difficulty = difficulty
self.numberOfGames = numberOfGames
self.gamesPlayed = 0
self.playerScore = 0
self.opponentScore = 0
self.playerIsNotFirst = False
self.gamesCounter = QLabel()
self.gamesCounter.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
self.updateGameCounter()
mainLayout = QVBoxLayout()
self.gameWidget = BotGame(self.getOpponent())
self.gameWidget.gameEnded.connect(self.updateScoreAndReset)
self.saveButton = QPushButton('Save series')
self.saveButton.clicked.connect(self.saveGame)
self.message = self.createLabel('')
self.message.hide()
mainLayout.addLayout(self.createScoreLayout())
mainLayout.addWidget(self.gameWidget)
mainLayout.addWidget(self.message)
pack = self.packInHStretch([self.gamesCounter, self.saveButton])
mainLayout.addLayout(pack)
self.setLayout(mainLayout)
def createScoreLayout(self):
self.playerScoreLcd = QLCDNumber(2)
self.playerScoreLcd.setSegmentStyle(QLCDNumber.Filled)
self.playerScoreLcd.setMinimumSize(75, 50)
self.playerScoreLcd.display(0)
self.opponentScoreLcd = QLCDNumber(2)
self.opponentScoreLcd.setSegmentStyle(QLCDNumber.Filled)
self.opponentScoreLcd.setMinimumSize(75, 50)
self.opponentScoreLcd.display(0)
layout = QHBoxLayout()
layout.addStretch(1)
layout.addWidget(self.createLabel('You: '))
layout.addWidget(self.playerScoreLcd)
layout.addStretch(1)
layout.addWidget(self.createLabel('Opponent: '))
layout.addWidget(self.opponentScoreLcd)
layout.addStretch(1)
return layout
def packInHStretch(self, widgets):
layout = QHBoxLayout()
layout.addStretch(1)
for widget in widgets:
layout.addWidget(widget)
layout.addStretch(1)
return layout
def displayMessage(self, message):
self.message.setText(message)
self.message.show()
self.repaint()
def hideMessage(self):
self.message.hide()
self.repaint()
def updateScoreAndReset(self):
self.gamesPlayed += 1
self.playerIsNotFirst = not self.playerIsNotFirst
result = self.gameWidget.board.state
message = ''
if result == game.boards.State.X_WON:
self.playerScore += 3
message = 'Congrats! You won the game!'
elif result == game.boards.State.O_WON:
self.opponentScore += 3
message = 'Sorry! You lost the game!'
elif result == game.boards.State.DRAW:
self.playerScore += 1
self.opponentScore += 1
message = 'The game ended in a draw!'
self.displayMessage(message)
self.playerScoreLcd.display(self.playerScore)
self.opponentScoreLcd.display(self.opponentScore)
if self.numberOfGames > self.gamesPlayed:
for i in range(3, 0, -1):
self.displayMessage(message + ' New game starting in ' +
str(i))
time.sleep(1)
self.hideMessage()
self.gameWidget.reset(self.playerIsNotFirst)
self.updateGameCounter()
else:
self.announceResult()
def announceResult(self):
if self.playerScore > self.opponentScore:
self.displayMessage('Congrats! You won the series!')
elif self.playerScore < self.opponentScore:
self.displayMessage('Sorry. You lost the series!')
else:
#.........这里部分代码省略.........