I am new to PyQt5 and want to make an app with custom titlebar. So i removed it and placed three macos like buttons in which if a user clicks on the green button, it minimizes the window, but it just closes the window instead of minimizing it . It is giving me this error:
Qt Code:
  1. TypeError: min() takes 1 positional argument but 2 were given
To copy to clipboard, switch view to plain text mode 
Here is my code:

Qt Code:
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QWidget
  3. from PyQt5.QtGui import QCursor, QWindow
  4.  
  5. class Ui_MainWindow(QWidget):
  6. def __init__(self):
  7. super().__init__()
  8. self.setWindowTitle("Wally")
  9. self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
  10.  
  11. # background
  12. self.label = QLabel("", self)
  13. background = QtGui.QPixmap(r"C:\Users\intel\Desktop\Wally\Background.png")
  14. background = background.scaled(1357, 728)
  15. self.label.setPixmap(background)
  16. self.label.show()
  17.  
  18. # red button
  19. self.label1 = QLabel("", self)
  20. red = QtGui.QPixmap(r"C:\Users\intel\Desktop\Wally\red.png")
  21. red = red.scaled(11, 11)
  22. self.label1.setPixmap(red)
  23. self.label1.show()
  24. self.label1.move(11,11)
  25. self.label1.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
  26.  
  27. # yellow button
  28. self.label2 = QLabel("", self)
  29. yellow = QtGui.QPixmap(r"C:\Users\intel\Desktop\Wally\yellow.png")
  30. yellow = yellow.scaled(11, 11)
  31. self.label2.setPixmap(yellow)
  32. self.label2.show()
  33. self.label2.move(30,11)
  34. self.label2.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
  35.  
  36. # green button
  37. self.label3 = QLabel("", self)
  38. green = QtGui.QPixmap(r"C:\Users\intel\Desktop\Wally\green.png")
  39. green = green.scaled(19, 11)
  40. self.label3.setPixmap(green)
  41. self.label3.show()
  42. self.label3.move(44,11)
  43. self.label3.setCursor(QCursor(QtCore.Qt.PointingHandCursor))
  44. self.label3.mousePressEvent = self.min
  45.  
  46. self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
  47. self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
  48. self.offset = None
  49.  
  50. def min(self):
  51. self.setWindowState(QWindow.Minimized)
  52.  
  53. def setupUi(self, MainWindow):
  54. MainWindow.setObjectName("MainWindow")
  55. MainWindow.resize(1920, 1000)
  56. #MainWindow.move(50,50)
  57.  
  58.  
  59. if __name__ == "__main__":
  60. import sys
  61. app = QtWidgets.QApplication(sys.argv)
  62. MainWindow = Ui_MainWindow()
  63. ui = Ui_MainWindow()
  64. ui.setupUi(MainWindow)
  65. MainWindow.show()
  66. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode