Certainly! Below is a comprehensive PyQt6 GUI application for a daily planner that records various daily activities such as tasks, gratitude, study hours, today's song, wake-up time, and today's motivation. The application features a hamburger menu for navigation, iPhone-style buttons with animations, and a color scheme based on the provided hex codes.
Key Features:
- Hamburger Menu: A side menu that slides in and out with animation, allowing navigation between different sections.
- iPhone-style Buttons: Rounded buttons with smooth animations on hover and click.
- Color Scheme: Utilizes the provided colors to create an aesthetically pleasing interface.
- Sections: Dedicated sections for Daily Tasks, Gratitude, Study Hours, Today's Song, Wake Up Time, and Today's Motivation.
Prerequisites:
- Ensure you have Python 3 installed.
- Install PyQt6 using pip if you haven't already:
pip install PyQt6
Complete Code:
import sys
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QWidget, QPushButton, QLabel,
QVBoxLayout, QHBoxLayout, QStackedWidget, QLineEdit, QTextEdit,
QTimeEdit
)
from PyQt6.QtCore import Qt, QPropertyAnimation, QEasingCurve, QRect, QSize, QTime
from PyQt6.QtGui import QIcon, QFont
# Define color palette
COLOR_PRIMARY = "#96CEB4" # Teal
COLOR_SECONDARY = "#FFAD60" # Orange
COLOR_ACCENT = "#A02334" # Red
COLOR_BACKGROUND = "#FFEEAD" # Light Yellow
class AnimatedButton(QPushButton):
def __init__(self, text):
super().__init__(text)
self.setFont(QFont("Arial", 12))
self.setStyleSheet(f"""
QPushButton {{
background-color: {COLOR_PRIMARY};
border: none;
color: white;
padding: 10px 20px;
border-radius: 15px;
}}
QPushButton:hover {{
background-color: {COLOR_SECONDARY};
}}
QPushButton:pressed {{
background-color: {COLOR_ACCENT};
}}
""")
self.setCursor(Qt.CursorShape.PointingHandCursor)
self.setFixedHeight(40)
class HamburgerButton(QPushButton):
def __init__(self, callback):
super().__init__()
self.callback = callback
self.setFixedSize(30, 30)
self.setStyleSheet("""
QPushButton {
border: none;
background-color: transparent;
}
QPushButton::hover {
background-color: #dddddd;
border-radius: 5px;
}
""")
def paintEvent(self, event):
painter = QIcon.fromTheme("open-menu")
super().paintEvent(event)
class SideMenu(QWidget):
def __init__(self, switch_page_callback):
super().__init__()
self.setFixedWidth(200)
self.setStyleSheet(f"background-color: {COLOR_BACKGROUND};")
layout = QVBoxLayout()
layout.setAlignment(Qt.AlignmentFlag.Top)
# Menu Buttons
buttons = [
("Daily Tasks", lambda: switch_page_callback(0)),
("Gratitude", lambda: switch_page_callback(1)),
("Study Hours", lambda: switch_page_callback(2)),
("Today's Song", lambda: switch_page_callback(3)),
("Wake Up Time", lambda: switch_page_callback(4)),
("Today's Motivation", lambda: switch_page_callback(5)),
]
for btn_text, callback in buttons:
btn = AnimatedButton(btn_text)
btn.clicked.connect(callback)
layout.addWidget(btn)
layout.addStretch()
self.setLayout(layout)
class MainContent(QStackedWidget):
def __init__(self):
super().__init__()
self.addWidget(self.daily_tasks_page())
self.addWidget(self.gratitude_page())
self.addWidget(self.study_hours_page())
self.addWidget(self.todays_song_page())
self.addWidget(self.wake_up_time_page())
self.addWidget(self.todays_motivation_page())
def daily_tasks_page(self):
page = QWidget()
layout = QVBoxLayout()
label = QLabel("Daily Tasks")
label.setFont(QFont("Arial", 16))
self.tasks_input = QTextEdit()
self.tasks_input.setPlaceholderText("Enter your tasks for today...")
layout.addWidget(label)
layout.addWidget(self.tasks_input)
page.setLayout(layout)
return page
def gratitude_page(self):
page = QWidget()
layout = QVBoxLayout()
label = QLabel("Gratitude")
label.setFont(QFont("Arial", 16))
self.gratitude_input = QTextEdit()
self.gratitude_input.setPlaceholderText("What are you grateful for today?")
layout.addWidget(label)
layout.addWidget(self.gratitude_input)
page.setLayout(layout)
return page
def study_hours_page(self):
page = QWidget()
layout = QVBoxLayout()
label = QLabel("Study Hours")
label.setFont(QFont("Arial", 16))
self.study_input = QLineEdit()
self.study_input.setPlaceholderText("Enter number of study hours...")
layout.addWidget(label)
layout.addWidget(self.study_input)
page.setLayout(layout)
return page
def todays_song_page(self):
page = QWidget()
layout = QVBoxLayout()
label = QLabel("Today's Song")
label.setFont(QFont("Arial", 16))
self.song_input = QLineEdit()
self.song_input.setPlaceholderText("Enter today's song...")
layout.addWidget(label)
layout.addWidget(self.song_input)
page.setLayout(layout)
return page
def wake_up_time_page(self):
page = QWidget()
layout = QVBoxLayout()
label = QLabel("Wake Up Time")
label.setFont(QFont("Arial", 16))
self.time_input = QTimeEdit()
self.time_input.setDisplayFormat("HH:mm")
self.time_input.setTime(QTime.currentTime())
layout.addWidget(label)
layout.addWidget(self.time_input)
page.setLayout(layout)
return page
def todays_motivation_page(self):
page = QWidget()
layout = QVBoxLayout()
label = QLabel("Today's Motivation")
label.setFont(QFont("Arial", 16))
self.motivation_input = QTextEdit()
self.motivation_input.setPlaceholderText("Enter your motivation for today...")
layout.addWidget(label)
layout.addWidget(self.motivation_input)
page.setLayout(layout)
return page
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Daily Planner")
self.setGeometry(100, 100, 800, 600)
self.setStyleSheet(f"background-color: {COLOR_PRIMARY};")
# Central Widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
# Main Layout
main_layout = QHBoxLayout()
central_widget.setLayout(main_layout)
# Side Menu
self.side_menu = SideMenu(self.switch_page)
self.side_menu.setVisible(False) # Hidden by default
main_layout.addWidget(self.side_menu)
# Main Content
self.content = MainContent()
main_layout.addWidget(self.content)
# Top Bar with Hamburger Button
self.top_bar = QHBoxLayout()
self.hamburger = AnimatedButton("☰")
self.hamburger.setFixedSize(30,30)
self.hamburger.setStyleSheet("""
QPushButton {
background-color: transparent;
color: white;
border: none;
font-size: 18px;
}
QPushButton:hover {
color: #FFAD60;
}
""")
self.hamburger.clicked.connect(self.toggle_menu)
top_container = QWidget()
top_layout = QHBoxLayout()
top_layout.addWidget(self.hamburger)
top_layout.addStretch()
top_container.setLayout(top_layout)
main_layout.setContentsMargins(0, 0, 0, 0)
main_layout.addLayout(self.top_bar)
# Animation for Side Menu
self.menu_animation = QPropertyAnimation(self.side_menu, b"maximumWidth")
self.menu_animation.setDuration(300)
self.menu_animation.setEasingCurve(QEasingCurve.Type.InOutQuad)
self.menu_visible = False
def toggle_menu(self):
if self.menu_visible:
# Hide menu
self.menu_animation.setStartValue(200)
self.menu_animation.setEndValue(0)
self.menu_animation.start()
self.side_menu.setVisible(False)
self.menu_visible = False
else:
# Show menu
self.side_menu.setVisible(True)
self.menu_animation.setStartValue(0)
self.menu_animation.setEndValue(200)
self.menu_animation.start()
self.menu_visible = True
def switch_page(self, index):
self.content.setCurrentIndex(index)
self.toggle_menu()
def main():
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()
Explanation of the Code:
-
Color Palette: The specified colors are defined at the beginning for easy customization and consistency throughout the application.
-
AnimatedButton Class: Inherits from QPushButton and applies custom styles to resemble iPhone-like buttons. It includes hover and pressed states with color transitions.
-
HamburgerButton & SideMenu Classes:
HamburgerButton is styled to represent the hamburger icon. However, to keep it simple and focused on functionality, the text "☰" is used to depict the hamburger symbol.
SideMenu contains buttons for navigating between different sections. It uses the AnimatedButton for consistency and aesthetic appeal.
-
MainContent Class: Utilizes QStackedWidget to manage different sections/pages of the planner. Each method (daily_tasks_page, gratitude_page, etc.) creates a separate page with appropriate input fields.
-
MainWindow Class:
- Sets up the main layout with a hidden side menu that can be toggled using the hamburger button.
- Implements the slide-in and slide-out animations for the side menu using
QPropertyAnimation.
- Contains a top bar with the hamburger button to control the visibility of the side menu.
- The
switch_page method changes the current view in the QStackedWidget based on the user's selection from the side menu.
-
Main Function: Initializes the application and displays the main window.
Running the Application:
-
Save the Code: Save the above code in a Python file, e.g., daily_planner.py.
-
Run the Application:
python daily_planner.py
-
Using the Planner:
- Click the hamburger button (☰) to open the side menu.
- Select any section to navigate to it.
- Input your daily tasks, gratitude entries, study hours, today's song, wake-up time, and today's motivation.
- The buttons will have hover and click animations, enhancing the user experience.
Notes:
- Persistence: This basic version does not include data persistence. To save and load data, you can enhance the application by integrating file handling or a database.
- Animations: The side menu smoothly slides in and out. Button animations are handled through CSS styling for hover and pressed states.
- Customization: Feel free to modify fonts, button sizes, and other UI elements to better suit your preferences.
This application provides a solid foundation for a daily planner with a clean and modern interface. You can further expand its functionality by adding features like reminders, calendar integrations, or data visualization based on your requirements.