|
1 | 1 | #!/usr/bin/python3
|
2 | | -# Calendar v1.0 |
3 | 2 | #
|
4 | 3 |
|
5 | 4 | from PyQt5.QtWidgets import *
|
6 | 5 | from PyQt5.QtCore import *
|
7 | 6 | from PyQt5.QtGui import *
|
| 7 | +from PyQt5.uic import loadUi |
8 | 8 | import sys
|
9 | 9 |
|
10 | | -class Window(QWidget): |
| 10 | +class Window(QMainWindow): |
11 | 11 | def __init__(self):
|
12 | 12 | super(Window,self).__init__()
|
13 | | - global date |
14 | | - self.setWindowTitle("Calendar") |
15 | | - self.setGeometry(500,100,500,400) |
16 | | - self.setFixedSize(500,400) |
17 | | - cal = QCalendarWidget(self) |
18 | | - cal.setGridVisible(True) |
19 | | - cal.move(50,30) |
20 | | - cal.clicked[QDate].connect(self.show_date) |
21 | | - self.lbl = QLabel(self) |
22 | | - self.lbl.setFont(QFont("Arial",18)) |
23 | | - self.lbl.setGeometry(145,255,400,100) |
24 | | - # self.lbl.move(170,300) |
25 | | - date = cal.selectedDate() |
26 | | - self.lbl.setText(date.toString("yyyy:MM:dd")) |
27 | | - |
28 | | - def show_date(self,date): |
29 | | - self.lbl.setText(date.toString()) |
| 13 | + loadUi("form.ui",self) |
| 14 | + self.setWindowTitle("تقویم") |
| 15 | + self.calendar.selectionChanged.connect(self.change_date) |
| 16 | + |
| 17 | + def change_date(self): |
| 18 | + date = self.calendar.selectedDate() |
| 19 | + self.label.setText(f"تاریخ: {str(date.toPyDate())}") |
30 | 20 |
|
31 | 21 |
|
32 | 22 | def main():
|
33 | | - # Calendar v1.0 |
34 | 23 | app = QApplication(sys.argv)
|
35 | | - app.setApplicationName("Calendar") |
36 | | - app.setApplicationVersion("v1.0") |
37 | 24 | window = Window()
|
38 | 25 | window.show()
|
39 | | - app.exec_() |
| 26 | + sys.exit(app.exec_()) |
40 | 27 |
|
41 | 28 | if __name__ == "__main__":
|
42 | 29 | main()
|
| 30 | + |
0 commit comments