import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout,QMainWindow, QAction, qApp
from PyQt5.QtCore import QCoreApplication
import random
class rps():
def btn1_click(self):
print("you played rock.")
np=random.randint(0,2)
up=0
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("rock >>", end=" ")
if np==up:
print("Tie")
elif np==1:
print("Computer win")
else:
print("User win")
def btn2_click(self):
print("you played paper.")
np=random.randint(0,2)
up=1
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("paper >>", end=" ")
if np==up:
print("Tie")
elif np==2:
print("Computer win")
else:
print("User win")
def btn3_click(self):
print("you played scissors.")
np=random.randint(0,2)
up=2
print("Computer vs user :", end=" ")
if np == 0:
print("rock vs", end=" ")
elif np == 1:
print("paper vs", end=" ")
elif np == 2:
print("scissors vs", end=" ")
print("scissors >>", end=" ")
if np==up:
print("Tie")
elif np==0:
print("Computer win")
else:
print("User win")
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
btn1 = QPushButton('&Rock', self)
btn1.setToolTip('Press to play <b>Rock</b>')
btn2 = QPushButton(self)
btn2.setText('&Paper')
btn2.setToolTip('Press to play <b>Paper</b>')
btn3 = QPushButton('&scissors', self)
btn3.setToolTip('Press to play <b>Scissors</b>')
vbox = QVBoxLayout()
vbox.addWidget(btn1)
vbox.addWidget(btn2)
vbox.addWidget(btn3)
btn1.clicked.connect(lambda:rps.btn1_click(self))
btn2.clicked.connect(lambda: rps.btn2_click(self))
btn3.clicked.connect(lambda: rps.btn3_click(self))
btn1.setStyleSheet("color: Blue;"
"background-color: #FF0000")
btn2.setStyleSheet("color: Purple;"
"background-color: #FFFF00")
btn3.setStyleSheet("color: Orange;"
"background-color: #0000FF")
self.setLayout(vbox)
self.setWindowTitle('Rock paper scissors')
self.setGeometry(300, 300, 300, 200)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())