Advertisement
Dynamic_Fantasy

Todo_Gui(PyQt6)

Aug 13th, 2023 (edited)
1,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.41 KB | Software | 0 0
  1. from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLineEdit, QPushButton, QListWidget, QListWidgetItem ,QCheckBox
  2. from PyQt6.QtGui import QFont  , QIcon
  3.  
  4. '''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 '''
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. class TodoApp(QMainWindow):
  13.     def __init__(self):
  14.         super().__init__()
  15.  
  16.         self.setWindowTitle("To-Do")
  17.         self.setGeometry(100, 100, 320, 420)
  18.         self.setWindowIcon(QIcon("qt_test/cursed2.png"))
  19.         self.setStyleSheet("""background-color : #121212""")
  20.  
  21.         #self.setStyleSheet("border : 2px solid #d207e8 ")
  22.        
  23.  
  24.         self.theme()
  25.  
  26.     def theme(self):
  27.         main_widget = QWidget(self)
  28.         main_widget.setStyleSheet("""
  29.        
  30.        background-color : #1e1e1e ;
  31.        border-radius :9px;                     /*you can set the border radius here*/
  32.                                  
  33.        border : 2px solid #bb86fc ;
  34.  
  35.  
  36.    
  37.  
  38.        """)
  39.         self.setCentralWidget(main_widget)
  40.  
  41.         layout = QVBoxLayout()
  42.        
  43.  
  44.         main_widget.setLayout(layout)
  45.  
  46.  
  47.         # this takes in the entry
  48.  
  49.         self.task_input = QLineEdit()        #using u+200e as a white space for padding
  50.                                            
  51.         self.task_input.setPlaceholderText("‎‎‎  Add Your New Todo.....")
  52.         self.task_input.setFont(QFont("calibri" , 17))
  53.         self.task_input.setStyleSheet("""
  54.        QLineEdit{
  55.                background-color :#2c2c2c ;
  56.                color :#f5f5f5;
  57.                height : 50px;
  58.                width : 100px;
  59.                border-radius : 25px;
  60.                border : 2px solid #871bec ;                
  61.        }
  62.        QLineEdit:hover{
  63.                
  64.                border : 2px solid #d128a6;                
  65.        }
  66.          
  67.        """)
  68.  
  69.         #adding  "add" button to widget
  70.  
  71.         add_button = QPushButton("Add Task")
  72.         add_button.setFont(QFont("calibri" , 15 , QFont.Weight.ExtraBold))
  73.         add_button.setStyleSheet("""
  74.            QPushButton{
  75.                    background-color: #871bec;
  76.                    color: white;
  77.                    height : 50px;
  78.                    width : 100px;
  79.                    border: 4px solid #871bec ;
  80.                    
  81.            }
  82.            QPushButton:hover{
  83.                    background-color :  #9603a3;
  84.                    font-size : 20;
  85.                     border: 1px solid ;
  86.                                            }
  87.                                
  88.            QPushButton:pressed {
  89.              border: 1px solid;
  90.                                            }
  91.                                
  92.        """)
  93.  
  94.         self.task_list = QListWidget()
  95.         #self.task_list.setFont(QFont("sans-serif " , 15))
  96.  
  97.         self.task_list.setStyleSheet("""
  98.            
  99.            background-color :#2d2d2d;
  100.            color : white ;
  101.            width = 20px
  102.            border-radius : 3px;
  103.            font-family: Arial;
  104.            font-size: 18px;
  105.            """)
  106.  
  107.         layout.addWidget(self.task_input)
  108.         layout.addWidget(add_button)
  109.         layout.addWidget(self.task_list)
  110.  
  111.         add_button.clicked.connect(self.add_task)
  112.  
  113.     def add_task(self):
  114.         task_text = self.task_input.text()
  115.        
  116.  
  117.  
  118.  
  119.    
  120.        
  121.         if task_text:           #doesnt take white space as input
  122.  
  123.             task_item = QListWidgetItem(task_text.title())
  124.             chk = QCheckBox(task_text.title())
  125.            
  126.  
  127.             chk.setChecked(False)
  128.             chk.toggled.connect(self.chk_button)
  129.             self.task_list.addItem(task_item)
  130.             self.task_list.setItemWidget(task_item,chk)  
  131.             self.task_input.clear()  #resets the input box to none
  132.    
  133.    
  134.    
  135.    
  136.     def chk_button(self):
  137.         chk = self.sender()   #takes in the checked input
  138.  
  139.         if chk.isChecked():     #checks if button's been smashed
  140.             self.remove()       #calls the remove function
  141.  
  142.  
  143.     def remove(self):    #deletes the item
  144.         list_row = self.task_list.currentRow()
  145.         temp_value = self.task_list.takeItem(list_row)
  146.         del temp_value
  147.            
  148.  
  149. app = QApplication([])
  150. window = TodoApp()
  151. window.show()
  152. app.exec()
  153.  
  154.  
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement