-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calendar GUI.py
166 lines (117 loc) · 4.07 KB
/
Calendar GUI.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QDate
from PyQt5.QtGui import QPixmap
import numpy as np
from datetime import datetime
import calendar
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(50, 50, 1080, 640)
self.setWindowTitle("PYQT5 App")
# self.tabs()
# self.listW()
# self.textEditor()
# self.slider()
# self.table()
# self.spinbox()
# self.image()
self.calendar()
self.show()
def tabs(self):
mainLayout = QVBoxLayout()
self.tab = QTabWidget()
self.tab1 = QWidget()
self.tab2 = QWidget()
self.tab3 = QWidget()
vbox = QVBoxLayout()
hbox = QHBoxLayout()
hbox2 = QHBoxLayout()
self.button1 = QPushButton("First tab")
self.button2 = QPushButton("Second tab")
self.button3 = QPushButton("Third tab")
vbox.addWidget(self.button1)
hbox.addWidget(self.button2)
hbox2.addWidget(self.button3)
self.tab1.setLayout(vbox)
self.tab2.setLayout(hbox)
self.tab3.setLayout(hbox2)
self.tab.addTab(self.tab1, "First")
self.tab.addTab(self.tab2, "Second")
self.tab.addTab(self.tab3, "Third")
mainLayout.addWidget(self.tab)
self.setLayout(mainLayout)
def listW(self):
self.list = QListWidget(self)
c = 2019
for i in range(10):
self.list.addItem(str(c-i))
def textEditor(self):
self.editor = QTextEdit(self)
self.editor.move(50, 50)
button = QPushButton("Text Editor", self)
button.move(50, 25)
button.clicked.connect(self.textEditorFunction)
def textEditorFunction(self):
text = self.editor.toPlainText()
print(text)
def slider(self):
vbox = QVBoxLayout()
self.slider = QSlider(Qt.Horizontal)
self.slider.setMinimum(0)
self.slider.setMaximum(100)
self.slider.setTickInterval(10)
self.slider.setTickPosition(QSlider.TicksBelow)
self.slider.valueChanged.connect(self.sliderFunction)
vbox.addWidget(self.slider)
vbox.addStretch()
self.setLayout(vbox)
def sliderFunction(self):
print(self.slider.value())
def table(self):
vbox = QVBoxLayout()
self.table = QTableWidget()
self.table.setRowCount(2)
self.table.setColumnCount(2)
self.table.setHorizontalHeaderItem(0, QTableWidgetItem("method1"))
self.table.setHorizontalHeaderItem(1, QTableWidgetItem("method2"))
arr = np.array([[1, 2], [3, 4]])
for r in range(arr.shape[0]):
for c in range(arr.shape[1]):
self.table.setItem(r, c, QTableWidgetItem(str(arr[r, c])))
button = QPushButton("Table")
button.clicked.connect(self.getValue)
vbox.addWidget(self.table)
vbox.addWidget(button)
self.setLayout(vbox)
def getValue(self):
for item in self.table.selectedItems():
print("Value: {}, row: {}, column: {}".format(
item.text(), item.row(), item.column()))
def spinbox(self):
self.spinbox = QSpinBox(self)
self.spinbox.move(50, 50)
self.spinbox.setRange(30, 40)
self.spinbox.setSingleStep(1)
self.spinbox.setSuffix(" $")
button = QPushButton("spin button", self)
button.move(50, 25)
button.clicked.connect(self.spinFunction)
def spinFunction(self):
print(self.spinbox.value())
def image(self):
self.image = QLabel(self)
self.image.setPixmap(QPixmap("icon1.png"))
self.image.move(50, 50)
def calendar(self):
self.calendar = QCalendarWidget(self)
self.calendar.move(20, 20)
self.calendar.setGridVisible(True)
self.calendar.clicked.connect(self.printDateInfo)
def printDateInfo(self, qDate):
print("{}/{}/{}".format(qDate.month(), qDate.day(), qDate.year()))
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()