当前位置: 首页>>代码示例>>Python>>正文


Python QLCDNumber.setMinimumSize方法代码示例

本文整理汇总了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:
#.........这里部分代码省略.........
开发者ID:stoimenoff,项目名称:ultimate-tic-tac-toe,代码行数:103,代码来源:singleplayergame.py


注:本文中的PyQt5.QtWidgets.QLCDNumber.setMinimumSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。