import sys
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import random
m=6
s=0
def guessodd(la2,la1):
global m
global s
print("number:",end=" ")
r=random.randint(1,12)
print(r)
if r%2==1:
print("you guessed correctly. +1 marble")
m=m+1
s=s+1
else:
print("you guessed incorrectly. -1 marble")
m=m-1
# print(la2.t0ext())
la2.setText('Your marbles:'+str(m))
la1.setText('Your score:'+str(s))
la1.repaint()
la2.repaint()
if m<1:
la2.setText("You're out of marbles! please close the window.")
la2.repaint()
def guesseven(la2,la1):
global m
global s
print("number:", end=" ")
r = random.randint(1, 12)
print(r)
if r % 2 == 0:
print("you guessed correctly. +1 marble")
m = m + 1
s=s+1
else:
print("you guessed incorrectly. -1 marble")
m = m - 1
la2.setText('Your marbles:'+str(m))
la2.repaint()
la1.setText('Your score:'+str(s))
la1.repaint()
if m<1:
la2.setText("You're out of marbles! please close the window.")
la2.repaint()
class MyApp(QWidget):
global m
def __init__(self):
super().__init__()
def initUI(self):
label1 = QLabel('Your score:'+str(s), self)
label2 = QLabel('Your marbles:'+str(m), self)
btno=QPushButton('&odd',self)
btno.clicked.connect(lambda:guessodd(label2,label1))
btne = QPushButton('&even', self)
btne.clicked.connect(lambda: guesseven(label2,label1))
btno.setStyleSheet("color: green;"
"background-color: #DC143C")
btne.setStyleSheet("color: orange;"
"background-color: #4169E1")
label2.setStyleSheet("color: green;"
"border-style: solid;"
"border-width: 2px;"
"border-color: #037A76;"
"border-radius: 1px")
label1.setStyleSheet("color: purple;"
"border-style: solid;"
"border-width: 2px;"
"border-color: #ED1B76;"
"border-radius: 1px")
vbox = QVBoxLayout()
vbox.addWidget(btno)
vbox.addWidget(btne)
vbox.addWidget(label1)
vbox.addWidget(label2)
self.setLayout(vbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('odd or even')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
ex.initUI()
sys.exit(app.exec_())