1
|
import sys
|
2
|
from PyQt5.QtWidgets import *
|
3
|
from PyQt5.QtGui import *
|
4
|
from PyQt5.QtCore import (Qt, pyqtSignal, QRect)
|
5
|
from PyQt5 import uic
|
6
|
class Card1(QLabel):
|
7
|
clicked = pyqtSignal()
|
8
|
|
9
|
def __init__(self, parent=None):
|
10
|
QLabel.__init__(self, parent=parent)
|
11
|
self.setPixmap(QPixmap("Heart_king.png"))
|
12
|
self.setScaledContents(True)
|
13
|
self.opened = True
|
14
|
|
15
|
def mousePressEvent(self, ev):
|
16
|
self.clicked.emit()
|
17
|
|
18
|
def rotate(self):
|
19
|
image = "r.jpg" if self.opened else "Heart_king.png"
|
20
|
self.setPixmap(QPixmap(image))
|
21
|
self.opened = not self.opened
|
22
|
|
23
|
class Card2(QLabel):
|
24
|
clicked = pyqtSignal()
|
25
|
|
26
|
def __init__(self, parent=None):
|
27
|
QLabel.__init__(self, parent=parent)
|
28
|
self.setPixmap(QPixmap("Heart_ace.png"))
|
29
|
self.setScaledContents(True)
|
30
|
self.opened = True
|
31
|
|
32
|
def mousePressEvent(self, ev):
|
33
|
self.clicked.emit()
|
34
|
|
35
|
def rotate(self):
|
36
|
image = "r.jpg" if self.opened else "Heart_ace.png"
|
37
|
self.setPixmap(QPixmap(image))
|
38
|
self.opened = not self.opened
|
39
|
|
40
|
|
41
|
class Card(QLabel):
|
42
|
clicked = pyqtSignal()
|
43
|
def __init__(self, parent=None):
|
44
|
QLabel.__init__(self, parent=parent)
|
45
|
self.setPixmap(QPixmap("kw.png"))
|
46
|
self.setScaledContents(True)
|
47
|
self.opened = True
|
48
|
|
49
|
|
50
|
|
51
|
def mousePressEvent(self, ev):
|
52
|
self.clicked.emit()
|
53
|
|
54
|
def rotate(self):
|
55
|
image = "r.jpg" if self.opened else "kw.jpg"
|
56
|
self.setPixmap(QPixmap(image))
|
57
|
self.opened = not self.opened
|
58
|
|
59
|
class Widget(QWidget):
|
60
|
def __init__(self, parent=None):
|
61
|
QWidget.__init__(self, parent=parent)
|
62
|
self.init_ui()
|
63
|
|
64
|
def paintEvent(self, event):
|
65
|
painter = QPainter(self)
|
66
|
painter.drawPixmap(self.rect(), QPixmap("1.png"))
|
67
|
QWidget.paintEvent(self, event)
|
68
|
|
69
|
|
70
|
def init_ui(self):
|
71
|
card1 = Card1(self)
|
72
|
card2 = Card2(self)
|
73
|
card = Card(self)
|
74
|
card.clicked.connect(card.rotate)
|
75
|
card1.clicked.connect(card1.rotate)
|
76
|
card2.clicked.connect(card2.rotate)
|
77
|
card.move(590,90)
|
78
|
card1.move(540,200)
|
79
|
card2.move(640,200)
|
80
|
|
81
|
self.show()
|
82
|
|
83
|
|
84
|
|
85
|
class MainWindow(QMainWindow):
|
86
|
def __init__(self, parent=None):
|
87
|
QMainWindow.__init__(self, parent=parent)
|
88
|
self.setCentralWidget(Widget(self))
|
89
|
self.setGeometry(300,300,350,350)
|
90
|
self.setWindowTitle('Pyramid Solitaire')
|
91
|
self.setWindowIcon(QIcon("pyr.jpg"))
|
92
|
self.init_ui()
|
93
|
self.show()
|
94
|
|
95
|
def init_ui(self):
|
96
|
main_menu = self.menuBar()
|
97
|
main_menu.addMenu('Help')
|
98
|
exitAction = QAction('Exit', self)
|
99
|
exitAction.setShortcut('Ctrl+Q')
|
100
|
exitAction.setStatusTip('Exit application')
|
101
|
exitAction.triggered.connect(qApp.quit)
|
102
|
self.statusBar()
|
103
|
|
104
|
menubar = self.menuBar()
|
105
|
fileMenu = menubar.addMenu('&Exit')
|
106
|
fileMenu.addAction(exitAction)
|
107
|
self.show()
|
108
|
|
109
|
if __name__ == '__main__':
|
110
|
|
111
|
app = QApplication(sys.argv)
|
112
|
w = MainWindow()
|
113
|
q = Card1()
|
114
|
w.show()
|
115
|
sys.exit(app.exec_())
|