Develop a complete interactive virtual pet desktop in the corner of screen
- User
Develop a complete interactive virtual pet desktop in the corner of screen
- Assistant
Absolutely! Creating an interactive virtual pet that lives in the corner of your desktop is a fun project. Below, I’ll outline a complete solution using Python with the PyQt5 library, which is cross-platform and well-suited for desktop GUI applications. This pet will be a small, always-on-top window with a transparent background, simple animations, and basic interactivity (feeding, petting, etc.).
🐾 Virtual Pet Desktop App (Python + PyQt5)
Features
- Always-on-top, frameless, transparent window
- Animated pet (idle, happy, eating)
- Click to pet, right-click to feed
- Simple status (hunger, happiness)
- Runs in the corner of the screen
1. Prerequisites
Install Python 3.x and the required libraries:
pip install PyQt5 pillow
2. Prepare Pet Images
You’ll need a few small PNG images (with transparency) for the pet’s different states (e.g.,
idle.png,happy.png,eating.png). You can use your own or find free sprites online.For demonstration, let’s assume you have these files in the same folder as your script.
3. The Code
import sys import os from PyQt5.QtWidgets import QApplication, QLabel, QMenu, QAction, QWidget from PyQt5.QtGui import QPixmap, QPainter, QCursor from PyQt5.QtCore import Qt, QTimer, QPoint class VirtualPet(QWidget): def __init__(self): super().__init__() self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool) self.setAttribute(Qt.WA_TranslucentBackground) self.setFixedSize(128, 128) # Adjust to your image size # Load images self.images = { 'idle': QPixmap('idle.png'), 'happy': QPixmap('happy.png'), 'eating': QPixmap('eating.png') } self.state = 'idle' self.label = QLabel(self) self.label.setPixmap(self.images[self.state]) self.label.setGeometry(0, 0, 128, 128) # Pet stats self.hunger = 100 self.happiness = 100 # Timers self.status_timer = QTimer(self) self.status_timer.timeout.connect(self.update_status) self.status_timer.start(5000) # Every 5 seconds self.animation_timer = QTimer(self) self.animation_timer.timeout.connect(self.reset_state) # Move to bottom right corner screen = QApplication.primaryScreen().geometry() self.move(screen.width() - self.width() - 20, screen.height() - self.height() - 60) self.show() def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.pet() elif event.button() == Qt.RightButton: self.feed() elif event.button() == Qt.MiddleButton: self.show_menu(event.globalPos()) def show_menu(self, pos): menu = QMenu() quit_action = QAction('Quit', self) quit_action.triggered.connect(QApplication.quit) menu.addAction(quit_action) menu.exec_(pos) def pet(self): self.state = 'happy' self.happiness = min(100, self.happiness + 10) self.label.setPixmap(self.images[self.state]) self.animation_timer.start(1000) # 1 second happy def feed(self): self.state = 'eating' self.hunger = min(100, self.hunger + 20) self.label.setPixmap(self.images[self.state]) self.animation_timer.start(1500) # 1.5 seconds eating def reset_state(self): self.state = 'idle' self.label.setPixmap(self.images[self.state]) self.animation_timer.stop() def update_status(self): self.hunger = max(0, self.hunger - 5) self.happiness = max(0, self.happiness - 2) if self.hunger < 30 or self.happiness < 30: self.setWindowTitle("Your pet needs attention!") else: self.setWindowTitle("") # Optional: Drag to move def mouseMoveEvent(self, event): if event.buttons() == Qt.LeftButton: self.move(self.mapToGlobal(event.pos() - QPoint(self.width()//2, self.height()//2))) if __name__ == '__main__': app = QApplication(sys.argv) pet = VirtualPet() sys.exit(app.exec_())
4. How to Use
- Place your PNG images (
idle.png,happy.png,eating.png) in the same folder. - Run the script:
python virtual_pet.py - The pet appears in the bottom-right corner.
- Left-click: Pet (increases happiness)
- Right-click: Feed (increases hunger)
- Middle-click: Show menu (quit)
- Drag: Move the pet
5. Customization Ideas
- Add more animations (sleeping, playing, etc.)
- Add sound effects (use
QSound) - Save/load pet state
- Add a small GUI for stats
- Use animated GIFs or sprite sheets
Let me know if you want a more advanced version, or if you want a version in another language or framework!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.