-
Notifications
You must be signed in to change notification settings - Fork 1
/
To_do_List.py
70 lines (54 loc) · 2.24 KB
/
To_do_List.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
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class TodoApp(QWidget):
def __init__(self):
super().__init__()
self.initializeUI()
def initializeUI(self):
# Main widget properties
self.setWindowTitle('My Todo List')
self.setFixedSize(400, 500)
self.setStyleSheet("""
background-color: #fff5e9;
font-size: 16px;
""")
self.titleLabel = QLabel('My Todo List')
self.titleLabel.setFont(QFont('Arial', 24, QFont.Bold))
self.inputBox = QLineEdit()
self.inputBox.setStyleSheet('QLineEdit {background: white;}')
self.inputBox.setMinimumHeight(40)
self.addButton = QPushButton('Add')
self.addButton.setStyleSheet('QPushButton {background: #4CAF50; color: white;}')
self.addButton.clicked.connect(self.addTodo)
self.updateButton = QPushButton('Update')
self.updateButton.setStyleSheet('QPushButton {background: #2196f3; color: white;}')
self.updateButton.clicked.connect(self.updateTodo)
self.todoList = QListWidget()
self.todoList.setStyleSheet('QListWidget {background: white;}')
self.mainLayout = QVBoxLayout()
self.mainLayout.addWidget(self.titleLabel, alignment=Qt.AlignCenter)
self.mainLayout.addWidget(self.inputBox)
self.buttonLayout = QHBoxLayout()
self.buttonLayout.addWidget(self.addButton)
self.buttonLayout.addWidget(self.updateButton)
self.mainLayout.addLayout(self.buttonLayout)
self.mainLayout.addWidget(self.todoList)
self.setLayout(self.mainLayout)
def addTodo(self):
item = QListWidgetItem(self.inputBox.text())
item.setCheckState(Qt.Unchecked)
self.todoList.addItem(item)
self.inputBox.clear()
def updateTodo(self):
currentItem = self.todoList.currentItem()
if currentItem:
itemText = self.inputBox.text()
currentItem.setText(itemText)
self.inputBox.clear()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = TodoApp()
window.show()
app.exec()