-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_menu.py
67 lines (51 loc) · 2.23 KB
/
main_menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_HOR_POSITION = 550
SCREEN_VER_POSITION = 200
class MainWindow(QMainWindow):
win_change_signal = QtCore.pyqtSignal()
def __init__(self):
super().__init__()
# Background image and pallete for main window
self.bImage = QImage("images/main_menu.jpg")
self.palette = QPalette()
# Main menu buttons
self.enterNames = QPushButton('Select player', self)
self.quitButton = QPushButton('Quit', self)
# QWidget which stores buttons
self.qWidget = QWidget()
# Initialize main menu ui
self.init_ui()
def init_ui(self):
# Add background
self.setWindowTitle('Bubble-Bobble game')
self.setGeometry(SCREEN_HOR_POSITION, SCREEN_VER_POSITION, SCREEN_WIDTH, SCREEN_HEIGHT)
self.setFixedSize(SCREEN_WIDTH, SCREEN_HEIGHT)
self.palette.setBrush(QPalette.Window, QBrush(self.bImage))
self.setPalette(self.palette)
# Modify buttons
self.enterNames.setFixedSize(250, 50)
self.enterNames.setStyleSheet("background-color: #33ffff;""font: 25pt Comic Sans MS;""color: black;""border-radius: 20px;")
self.enterNames.clicked.connect(lambda : self.onEnterNames())
self.quitButton.setFixedSize(250, 50)
self.quitButton.setStyleSheet("background-color: #33ffff;""font: 25pt Comic Sans MS;""color: black;""border-radius: 20px;")
self.quitButton.clicked.connect(lambda : self.onQuitPressed())
# Add vertical layout
horizonal_layout = QVBoxLayout()
horizonal_layout.addWidget(self.enterNames)
horizonal_layout.addWidget(self.quitButton)
horizonal_layout.setAlignment(Qt.AlignBottom | Qt.AlignCenter)
# Add layout inside widget
self.qWidget.setLayout(horizonal_layout)
# Add central widget which contains buttons
self.setCentralWidget(self.qWidget)
def onQuitPressed(self):
print("onQuit pressed")
self.close()
def onEnterNames(self):
print("onEnterNamePressed")
self.win_change_signal.emit()