from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
sys
class
StringBox(QSpinBox):
def
__init__(
self
, parent
=
None
):
super
(StringBox,
self
).__init__(parent)
strings
=
["a", "b", "c", "d", "e", "f", "g"]
self
.setStrings(["BLANK"]
+
strings
+
["BLANK"])
self
.setValue(
1
)
def
reset_spin(
self
):
if
self
.value()
=
=
len
(
self
.strings())
-
1
:
self
.setValue(
0
)
def
setStrings(
self
, strings):
strings
=
list
(strings)
self
._strings
=
tuple
(strings)
self
._values
=
dict
(
zip
(strings,
range
(
len
(strings))))
self
.setRange(
0
,
len
(strings)
-
1
)
def
textFromValue(
self
, value):
return
self
._strings[value]
def
stepBy(
self
, step):
if
self
.value()
=
=
1
and
step
=
=
-
1
:
self
.setValue(
self
.maximum())
elif
self
.value()
=
=
self
.maximum()
-
1
and
step
=
=
1
:
self
.setValue(
0
)
QSpinBox.stepBy(
self
, step)
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle("Python ")
self
.setGeometry(
100
,
100
,
600
,
400
)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
string_spin_box
=
StringBox(
self
)
string_spin_box.setGeometry(
100
,
100
,
200
,
40
)
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())