from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
random
import
sys
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle("Python ")
self
.setGeometry(
100
,
100
,
320
,
350
)
self
.UiComponents()
self
.show()
self
.words
=
[
'red'
,
'cold'
,
'hot'
,
'geeks'
,
'rain'
,
'black'
,
'snow'
,
'hills'
,
'code'
]
self
.current_text
=
""
def
UiComponents(
self
):
head
=
QLabel("Jumbled Word Game",
self
)
head.setGeometry(
20
,
10
,
280
,
60
)
font
=
QFont(
'Times'
,
15
)
font.setBold(
True
)
font.setItalic(
True
)
font.setUnderline(
True
)
head.setFont(font)
head.setAlignment(Qt.AlignCenter)
color
=
QGraphicsColorizeEffect(
self
)
color.setColor(Qt.darkCyan)
head.setGraphicsEffect(color)
self
.j_word
=
QLabel(
self
)
self
.j_word.setGeometry(
30
,
80
,
260
,
50
)
self
.j_word.setStyleSheet("border :
2px
solid black; background : white;")
self
.j_word.setFont(QFont(
'Times'
,
12
))
self
.j_word.setAlignment(Qt.AlignCenter)
self
.
input
=
QLineEdit(
self
)
self
.
input
.setGeometry(
20
,
150
,
200
,
40
)
self
.
input
.setAlignment(Qt.AlignCenter)
self
.check
=
QPushButton("Check",
self
)
self
.check.setGeometry(
230
,
155
,
80
,
30
)
self
.check.clicked.connect(
self
.check_action)
self
.result
=
QLabel(
self
)
self
.result.setGeometry(
40
,
210
,
240
,
50
)
self
.result.setFont(QFont(
'Times'
,
13
))
self
.result.setAlignment(Qt.AlignCenter)
self
.result.setStyleSheet("border :
2px
solid black; background : yellow;")
start
=
QPushButton("Start",
self
)
reset
=
QPushButton("Reset",
self
)
start.setGeometry(
15
,
290
,
140
,
40
)
reset.setGeometry(
165
,
290
,
140
,
40
)
start.clicked.connect(
self
.start_action)
reset.clicked.connect(
self
.reset_action)
def
check_action(
self
):
text
=
self
.
input
.text()
if
text
=
=
self
.current_text:
self
.result.setText("Correct Answer")
self
.result.setStyleSheet("background : lightgreen;")
else
:
self
.result.setText("Wrong Answer")
self
.result.setStyleSheet("background : red;")
def
start_action(
self
):
self
.current_text
=
random.choice(
self
.words)
random_word
=
random.sample(
self
.current_text,
len
(
self
.current_text))
jumbled
=
''.join(random_word)
self
.j_word.setText(jumbled)
self
.result.setText("")
self
.result.setStyleSheet("border :
2px
solid black; background : yellow;")
self
.
input
.setText("")
def
reset_action(
self
):
self
.current_text
=
""
self
.
input
.setText("")
self
.j_word.setText("")
self
.result.setText("")
self
.result.setStyleSheet("border :
2px
solid black; background : yellow;")
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())