-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7312 from yousifj129/master
Create todoapp.py
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
Program's_Contributed_By_Contributors/Python_Programs/todoapp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import sys | ||
from PySide6.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidget, QLineEdit, QPushButton, QListView | ||
from PySide6.QtCore import QStringListModel | ||
|
||
class TodoListApp(QMainWindow): | ||
def __init__(self): | ||
super().__init__() | ||
self.setWindowTitle("Todo List App") | ||
self.setGeometry(100, 100, 400, 300) | ||
|
||
self.tasks = [] | ||
|
||
self.central_widget = QWidget() | ||
self.setCentralWidget(self.central_widget) | ||
|
||
self.layout = QVBoxLayout() | ||
self.central_widget.setLayout(self.layout) | ||
self.task_list = QListView() | ||
self.task_list.setEditTriggers(QListView.NoEditTriggers) | ||
self.task_list.setSelectionMode(QListView.SingleSelection) | ||
self.layout.addWidget(self.task_list) | ||
self.label = QLabel("Enter a task:") | ||
self.layout.addWidget(self.label) | ||
|
||
self.task_input = QLineEdit() | ||
self.layout.addWidget(self.task_input) | ||
|
||
self.add_button = QPushButton("Add") | ||
self.add_button.clicked.connect(self.add_task) | ||
self.layout.addWidget(self.add_button) | ||
|
||
self.remove_button = QPushButton("Remove") | ||
self.remove_button.clicked.connect(self.remove_task) | ||
self.layout.addWidget(self.remove_button) | ||
|
||
|
||
|
||
self.update_task_list() | ||
|
||
def add_task(self): | ||
task = self.task_input.text() | ||
if task: | ||
self.tasks.append(task) | ||
self.task_input.clear() | ||
self.update_task_list() | ||
|
||
def remove_task(self): | ||
selected_index = self.task_list.currentIndex() | ||
if selected_index.isValid(): | ||
task = self.tasks[selected_index.row()] | ||
self.tasks.remove(task) | ||
self.update_task_list() | ||
|
||
def update_task_list(self): | ||
self.task_list.setModel(QStringListModel(self.tasks)) | ||
|
||
if __name__ == "__main__": | ||
app = QApplication(sys.argv) | ||
window = TodoListApp() | ||
window.show() | ||
sys.exit(app.exec()) |