Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLineEdit, QPushButton, QListWidget, QListWidgetItem ,QCheckBox
- from PyQt6.QtGui import QFont , QIcon
- '''Here's a simple todo gui application i made with PyQt6 so yeah you should prolly give it a shot took me abt 2-3 days to wrap my head around the crazy stuff its been doin in the background '''
- class TodoApp(QMainWindow):
- def __init__(self):
- super().__init__()
- self.setWindowTitle("To-Do")
- self.setGeometry(100, 100, 320, 420)
- self.setWindowIcon(QIcon("qt_test/cursed2.png"))
- self.setStyleSheet("""background-color : #121212""")
- #self.setStyleSheet("border : 2px solid #d207e8 ")
- self.theme()
- def theme(self):
- main_widget = QWidget(self)
- main_widget.setStyleSheet("""
- background-color : #1e1e1e ;
- border-radius :9px; /*you can set the border radius here*/
- border : 2px solid #bb86fc ;
- """)
- self.setCentralWidget(main_widget)
- layout = QVBoxLayout()
- main_widget.setLayout(layout)
- # this takes in the entry
- self.task_input = QLineEdit() #using u+200e as a white space for padding
- self.task_input.setPlaceholderText(" Add Your New Todo.....")
- self.task_input.setFont(QFont("calibri" , 17))
- self.task_input.setStyleSheet("""
- QLineEdit{
- background-color :#2c2c2c ;
- color :#f5f5f5;
- height : 50px;
- width : 100px;
- border-radius : 25px;
- border : 2px solid #871bec ;
- }
- QLineEdit:hover{
- border : 2px solid #d128a6;
- }
- """)
- #adding "add" button to widget
- add_button = QPushButton("Add Task")
- add_button.setFont(QFont("calibri" , 15 , QFont.Weight.ExtraBold))
- add_button.setStyleSheet("""
- QPushButton{
- background-color: #871bec;
- color: white;
- height : 50px;
- width : 100px;
- border: 4px solid #871bec ;
- }
- QPushButton:hover{
- background-color : #9603a3;
- font-size : 20;
- border: 1px solid ;
- }
- QPushButton:pressed {
- border: 1px solid;
- }
- """)
- self.task_list = QListWidget()
- #self.task_list.setFont(QFont("sans-serif " , 15))
- self.task_list.setStyleSheet("""
- background-color :#2d2d2d;
- color : white ;
- width = 20px
- border-radius : 3px;
- font-family: Arial;
- font-size: 18px;
- """)
- layout.addWidget(self.task_input)
- layout.addWidget(add_button)
- layout.addWidget(self.task_list)
- add_button.clicked.connect(self.add_task)
- def add_task(self):
- task_text = self.task_input.text()
- if task_text: #doesnt take white space as input
- task_item = QListWidgetItem(task_text.title())
- chk = QCheckBox(task_text.title())
- chk.setChecked(False)
- chk.toggled.connect(self.chk_button)
- self.task_list.addItem(task_item)
- self.task_list.setItemWidget(task_item,chk)
- self.task_input.clear() #resets the input box to none
- def chk_button(self):
- chk = self.sender() #takes in the checked input
- if chk.isChecked(): #checks if button's been smashed
- self.remove() #calls the remove function
- def remove(self): #deletes the item
- list_row = self.task_list.currentRow()
- temp_value = self.task_list.takeItem(list_row)
- del temp_value
- app = QApplication([])
- window = TodoApp()
- window.show()
- app.exec()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement