At the beginning , I will show you how the code runs and what it looks like. The window has a transparent background with a solid white area inside the frame. This design is intended to provide you with a basic understanding of its functionality. You will need to add other functions to this window according to your own requirements.
Here is the code that you can directly run in your PyCharm or any other platform. Feel free to give it a try. Thank you!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget,QApplication,QMainWindow,QInputDialog
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class Ui_MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.resize(661, 490)
# =========================== # 主要代码
self.setWindowFlags(QtCore.Qt.WindowType.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
# =========================== #
self.centralwidget = QtWidgets.QWidget()
self.centralwidget.setObjectName("centralwidget")
self.frame = QtWidgets.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(0, 0, 661, 491))
self.frame.setStyleSheet("background-color: rgba(33, 151, 230, 110);")
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.frame_2 = QtWidgets.QFrame(self.frame)
self.frame_2.setGeometry(QtCore.QRect(10, 10, 231, 471))
self.frame_2.setStyleSheet("background-color: rgb(255, 251, 252);\n""border-radius:10px;")
self.frame_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_2.setObjectName("frame_2")
self.setCentralWidget(self.centralwidget)
def mousePressEvent(self, event):
self.oldPos = event.globalPos()
def mouseMoveEvent(self, event):
delta = QPoint (event.globalPos() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = Ui_MainWindow()
ui.show()
sys.exit(app.exec_())