pastabowl

Untitled

Oct 24th, 2025
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | Source Code | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from PyQt6.QtWidgets import (
  4.     QApplication, QWidget, QHBoxLayout, QVBoxLayout, QPushButton,
  5.     QFrame, QLabel, QSizePolicy, QSpacerItem
  6. )
  7. from PyQt6.QtGui import QPainter, QPaintEvent, QColor, QPen, QBrush, QMouseEvent
  8. from PyQt6.QtCore import Qt, QRect, QSize, QPointF
  9. import sys
  10.  
  11.  
  12. # noinspection SpellCheckingInspection
  13. class Bitton(QWidget):
  14.     def __init__(self):
  15.         super().__init__()
  16.         self.power: int= 0
  17.         self.state: bool = False
  18.         self.setMaximumSize(30, 30)
  19.  
  20.     def mouseReleaseEvent(self, a0):
  21.         self.state = not self.state
  22.         self.update()
  23.  
  24.     def paintEvent(self, pe: QPaintEvent):
  25.         pen_color: QColor = QColor("#30aa53") if self.state else QColor("#204023")
  26.         brush_color: QColor = QColor("#78ffa3") if self.state else QColor("#258022")
  27.         p: QPainter = QPainter(self)
  28.         p.setRenderHint(QPainter.RenderHint.Antialiasing)
  29.         p.setPen(QPen(pen_color, 3))
  30.         p.setBrush(brush_color)
  31.         p.drawRoundedRect(self.rect().toRectF(), 4.0, 4.0)
  32.         p.drawText(QPointF(), "0")
  33.  
  34.  
  35. class MainWindow(QWidget):
  36.     def __init__(self):
  37.         super().__init__()
  38.         self.setWindowTitle("Nonbinary, the Decimal/Binary/Hex Calculator")
  39.         self.resize(400, 400)
  40.         self.build_ui()
  41.  
  42.     def build_ui(self):
  43.         hLayout: QHBoxLayout = QHBoxLayout()
  44.         for b in range(8):
  45.             bit: Bitton = Bitton()
  46.             bit.power = b
  47.             hLayout.addWidget(bit)
  48.             if b == 3: hLayout.addSpacing(4)
  49.         self.setLayout(hLayout)
  50.  
  51.  
  52. def main():
  53.     app = QApplication(sys.argv)
  54.     w = MainWindow()
  55.     w.show()
  56.     sys.exit(app.exec())
  57.  
  58.  
  59. if __name__ == "__main__":
  60.     main()
  61.  
Advertisement
Add Comment
Please, Sign In to add comment