RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-469614

Захар Уляшов's questions

Martin Hope
Захар Уляшов
Asked: 2023-09-26 15:50:48 +0000 UTC

如何从 beautifulsoup4 输出中删除 <br/> 类

  • 5

我正在尝试解析一个网站。我正在使用 beaitufulsoup4 库。在 span 标签内,我需要获取除 br 标签之外的所有 b 标签及其内容。如果使用 .text 方法,则 br 标记后面的文本将被删除。如何才能做到这一点?

站点布局:

站点标记

我的代码:

def get_data():
    page = requests.get("https://www.forbes.ru/milliardery/487053-10-bogatejsih-ludej-mira-2023-rejting-forbes")

    soup = BeautifulSoup(page.text, "lxml")
    all_person = soup.find_all('figcaption', class_='EXdHT')
    for person in all_person:
        name = person.find('h2', class_='jYzxi').text
        about_person = person.find('div', class_='CFaZ3').find('p').find('span')
        print(about_person)

get_data()

终端输出: 端子输出

python
  • 2 个回答
  • 35 Views
Martin Hope
Захар Уляшов
Asked: 2022-08-16 23:31:17 +0000 UTC

其中一个方块坏了

  • 0

当我改变第三张卡片的最大宽度时,它变得比其他卡片小,尽管图像和内容是相同的。

.third-card, .second-card, .first-card {
  max-width: 350px;
  background-color: rgba(37, 38, 39, 0.9);
  margin: 0 0 0 50px;
  display: inline-block;
}

.third-card .image, .second-card .image, .first-card .image {
  width: 100%;
  min-height: 200px;
}

.first-card .image {
  background: url("../source/image.jpg") 0 0/100% 100% no-repeat;
}

.second-card .image {
  background: url("../source/sharm-6.jpg") 0 0/100% 100% no-repeat;
}

.third-card .image {
  background: url("../source/image.jpg") 0 0/100% 100% no-repeat;
}

.content {
  width: 100%;
  margin: 50px 70px;
  color: #fff;
  border: black solid 1px;
  vertical-align: middle;
}
.content .text {
  padding: 30px 25px;
}
.content .text * {
  display: inline-block;
  margin-bottom: 20px;
}

* {
  padding: 0;
  margin: 0;
  border: 0;
}

*, *::before, *::after {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/style.css">
    <title>Card</title>
</head>
<body>
    <div class="content">
        <div class="first-card">
            <div class="image"></div>
            <div class="text">
                <h1>Первый текст рыба</h1>
                <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloribus, repellat. Accusamus alias, est deleniti facere neque dolor, cupiditate vero qui ad quod ut. Pariatur voluptas libero animi esse, laborum error.</p>
                <span>Автор: Admin<br>Дата создания: 16.06.2022</span>
            </div>
        </div>

        <div class="second-card">
            <div class="image"></div>
            <div class="text">
                <h1>Второй текст рыба</h1>
                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fuga perferendis eos iste dolores exercitationem, officiis nisi officia magnam est excepturi, quam sunt quis aliquid, odit cupiditate ipsam dolor autem deleniti.</p>
                <span>Автор: Admin<br>Дата создания: 16.06.2022</span>
            </div>
        </div>

        <div class="third-card">
            <div class="image"></div>
            <div class="text">
                <h1>Третий текст рыба</h1>
                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fuga perferendis eos iste dolores exercitationem, officiis nisi officia magnam est excepturi, quam sunt quis aliquid, odit cupiditate ipsam dolor autem deleniti.</p>
                <span>Автор: Admin<br>Дата создания: 16.06.2022</span>
            </div>
        </div>
    </div>
</body>
</html>

卡片样式

卡片所在区块的样式

在此处输入图像描述 在此处输入图像描述

html css
  • 1 个回答
  • 24 Views
Martin Hope
Захар Уляшов
Asked: 2022-08-24 00:33:26 +0000 UTC

计算器不计算百分比

  • 1

我正在用PyQt5写一个计算器,我不能让它计算百分比

编码:

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(320, 540)
        MainWindow.setMinimumSize(QtCore.QSize(320, 460))
        MainWindow.setMaximumSize(QtCore.QSize(320, 540))
        MainWindow.setStyleSheet("")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.input_data = QtWidgets.QLineEdit(self.centralwidget)
        self.input_data.setGeometry(QtCore.QRect(0, 0, 320, 140))
        self.input_data.setMinimumSize(QtCore.QSize(320, 140))
        self.input_data.setMaximumSize(QtCore.QSize(320, 140))
        font = QtGui.QFont()
        font.setPointSize(30)
        self.input_data.setFont(font)
        self.input_data.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"border: none;\n"
"color: white;\n"
"")
        self.input_data.setText("")
        self.input_data.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.input_data.setObjectName("input_data")
        self.button7 = QtWidgets.QPushButton(self.centralwidget)
        self.button7.setGeometry(QtCore.QRect(0, 220, 81, 81))
        self.button7.setMinimumSize(QtCore.QSize(81, 81))
        self.button7.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button7.setFont(font)
        self.button7.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button7.setObjectName("button7")
        self.button8 = QtWidgets.QPushButton(self.centralwidget)
        self.button8.setGeometry(QtCore.QRect(80, 220, 81, 81))
        self.button8.setMinimumSize(QtCore.QSize(81, 81))
        self.button8.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button8.setFont(font)
        self.button8.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button8.setObjectName("button8")
        self.button9 = QtWidgets.QPushButton(self.centralwidget)
        self.button9.setGeometry(QtCore.QRect(160, 220, 81, 81))
        self.button9.setMinimumSize(QtCore.QSize(81, 81))
        self.button9.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button9.setFont(font)
        self.button9.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button9.setObjectName("button9")
        self.button4 = QtWidgets.QPushButton(self.centralwidget)
        self.button4.setGeometry(QtCore.QRect(0, 300, 81, 81))
        self.button4.setMinimumSize(QtCore.QSize(81, 81))
        self.button4.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button4.setFont(font)
        self.button4.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button4.setObjectName("button4")
        self.button5 = QtWidgets.QPushButton(self.centralwidget)
        self.button5.setGeometry(QtCore.QRect(80, 300, 81, 81))
        self.button5.setMinimumSize(QtCore.QSize(81, 81))
        self.button5.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button5.setFont(font)
        self.button5.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button5.setObjectName("button5")
        self.button6 = QtWidgets.QPushButton(self.centralwidget)
        self.button6.setGeometry(QtCore.QRect(160, 300, 81, 81))
        self.button6.setMinimumSize(QtCore.QSize(81, 81))
        self.button6.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button6.setFont(font)
        self.button6.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button6.setObjectName("button6")
        self.buttonpoint = QtWidgets.QPushButton(self.centralwidget)
        self.buttonpoint.setGeometry(QtCore.QRect(80, 460, 81, 81))
        self.buttonpoint.setMinimumSize(QtCore.QSize(81, 81))
        self.buttonpoint.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonpoint.setFont(font)
        self.buttonpoint.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.buttonpoint.setObjectName("buttonpoint")
        self.button0 = QtWidgets.QPushButton(self.centralwidget)
        self.button0.setGeometry(QtCore.QRect(0, 460, 81, 81))
        self.button0.setMinimumSize(QtCore.QSize(81, 81))
        self.button0.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button0.setFont(font)
        self.button0.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button0.setObjectName("button0")
        self.buttonc = QtWidgets.QPushButton(self.centralwidget)
        self.buttonc.setGeometry(QtCore.QRect(0, 140, 81, 81))
        self.buttonc.setMinimumSize(QtCore.QSize(81, 81))
        self.buttonc.setMaximumSize(QtCore.QSize(162, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonc.setFont(font)
        self.buttonc.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.buttonc.setObjectName("buttonc")
        self.button1 = QtWidgets.QPushButton(self.centralwidget)
        self.button1.setGeometry(QtCore.QRect(0, 380, 81, 81))
        self.button1.setMinimumSize(QtCore.QSize(81, 81))
        self.button1.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button1.setFont(font)
        self.button1.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button1.setObjectName("button1")
        self.button2 = QtWidgets.QPushButton(self.centralwidget)
        self.button2.setGeometry(QtCore.QRect(80, 380, 81, 81))
        self.button2.setMinimumSize(QtCore.QSize(81, 81))
        self.button2.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button2.setFont(font)
        self.button2.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button2.setObjectName("button2")
        self.button3 = QtWidgets.QPushButton(self.centralwidget)
        self.button3.setGeometry(QtCore.QRect(160, 380, 81, 81))
        self.button3.setMinimumSize(QtCore.QSize(81, 81))
        self.button3.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button3.setFont(font)
        self.button3.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.button3.setObjectName("button3")
        self.buttonbackspace = QtWidgets.QPushButton(self.centralwidget)
        self.buttonbackspace.setGeometry(QtCore.QRect(160, 140, 81, 81))
        self.buttonbackspace.setMinimumSize(QtCore.QSize(81, 81))
        self.buttonbackspace.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonbackspace.setFont(font)
        self.buttonbackspace.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.buttonbackspace.setObjectName("buttonbackspace")
        self.buttonadd = QtWidgets.QPushButton(self.centralwidget)
        self.buttonadd.setGeometry(QtCore.QRect(240, 140, 81, 81))
        self.buttonadd.setMinimumSize(QtCore.QSize(81, 81))
        self.buttonadd.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonadd.setFont(font)
        self.buttonadd.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(12, 66, 68);\n"
"    border-radius: 0px;\n"
"}\n"
"QPushButton:hover {\n"
"    background-color: rgb(18, 103, 106);\n"
"}")
        self.buttonadd.setObjectName("buttonadd")
        self.buttonsub = QtWidgets.QPushButton(self.centralwidget)
        self.buttonsub.setGeometry(QtCore.QRect(240, 220, 81, 81))
        self.buttonsub.setMinimumSize(QtCore.QSize(81, 81))
        self.buttonsub.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonsub.setFont(font)
        self.buttonsub.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(12, 66, 68);\n"
"    border-radius: 0px;\n"
"}\n"
"QPushButton:hover {\n"
"    background-color: rgb(18, 103, 106);\n"
"}")
        self.buttonsub.setObjectName("buttonsub")
        self.buttonmult = QtWidgets.QPushButton(self.centralwidget)
        self.buttonmult.setGeometry(QtCore.QRect(240, 300, 81, 81))
        self.buttonmult.setMinimumSize(QtCore.QSize(81, 81))
        self.buttonmult.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonmult.setFont(font)
        self.buttonmult.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(12, 66, 68);\n"
"    border-radius: 0px;\n"
"}\n"
"QPushButton:hover {\n"
"    background-color: rgb(18, 103, 106);\n"
"}")
        self.buttonmult.setObjectName("buttonmult")
        self.buttondiv = QtWidgets.QPushButton(self.centralwidget)
        self.buttondiv.setGeometry(QtCore.QRect(240, 380, 81, 81))
        self.buttondiv.setMinimumSize(QtCore.QSize(81, 81))
        self.buttondiv.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttondiv.setFont(font)
        self.buttondiv.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(12, 66, 68);\n"
"    border-radius: 0px;\n"
"}\n"
"QPushButton:hover {\n"
"    background-color: rgb(18, 103, 106);\n"
"}")
        self.buttondiv.setObjectName("buttondiv")
        self.buttonequally = QtWidgets.QPushButton(self.centralwidget)
        self.buttonequally.setGeometry(QtCore.QRect(160, 460, 162, 81))
        self.buttonequally.setMinimumSize(QtCore.QSize(162, 81))
        self.buttonequally.setMaximumSize(QtCore.QSize(162, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonequally.setFont(font)
        self.buttonequally.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(41, 174, 161);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(31, 135, 125);\n"
"}")
        self.buttonequally.setObjectName("buttonequally")
        self.history = QtWidgets.QLabel(self.centralwidget)
        self.history.setGeometry(QtCore.QRect(50, 20, 261, 20))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.history.setFont(font)
        self.history.setStyleSheet("color: rgb(34, 187, 187);")
        self.history.setText("")
        self.history.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.history.setObjectName("history")
        self.buttonprocent = QtWidgets.QPushButton(self.centralwidget)
        self.buttonprocent.setGeometry(QtCore.QRect(80, 140, 81, 81))
        self.buttonprocent.setMinimumSize(QtCore.QSize(81, 81))
        self.buttonprocent.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonprocent.setFont(font)
        self.buttonprocent.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(5, 15, 17);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    \n"
"    background-color: rgb(63, 63, 63);\n"
"}")
        self.buttonprocent.setObjectName("buttonprocent")
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.button7.setText(_translate("MainWindow", "7"))
        self.button8.setText(_translate("MainWindow", "8"))
        self.button9.setText(_translate("MainWindow", "9"))
        self.button4.setText(_translate("MainWindow", "4"))
        self.button5.setText(_translate("MainWindow", "5"))
        self.button6.setText(_translate("MainWindow", "6"))
        self.buttonpoint.setText(_translate("MainWindow", "."))
        self.button0.setText(_translate("MainWindow", "0"))
        self.buttonc.setText(_translate("MainWindow", "с"))
        self.button1.setText(_translate("MainWindow", "1"))
        self.button2.setText(_translate("MainWindow", "2"))
        self.button3.setText(_translate("MainWindow", "3"))
        self.buttonbackspace.setText(_translate("MainWindow", "<"))
        self.buttonadd.setText(_translate("MainWindow", "+"))
        self.buttonsub.setText(_translate("MainWindow", "-"))
        self.buttonmult.setText(_translate("MainWindow", "*"))
        self.buttondiv.setText(_translate("MainWindow", "/"))
        self.buttonequally.setText(_translate("MainWindow", "="))
        self.buttonprocent.setText(_translate("MainWindow", "%"))


class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.button0.clicked.connect(lambda: self.write_number(self.button0.text()))
        self.button1.clicked.connect(lambda: self.write_number(self.button1.text()))
        self.button2.clicked.connect(lambda: self.write_number(self.button2.text()))
        self.button3.clicked.connect(lambda: self.write_number(self.button3.text()))
        self.button4.clicked.connect(lambda: self.write_number(self.button4.text()))
        self.button5.clicked.connect(lambda: self.write_number(self.button5.text()))
        self.button6.clicked.connect(lambda: self.write_number(self.button6.text()))
        self.button7.clicked.connect(lambda: self.write_number(self.button7.text()))
        self.button8.clicked.connect(lambda: self.write_number(self.button8.text()))
        self.button9.clicked.connect(lambda: self.write_number(self.button9.text()))
        self.buttonpoint.clicked.connect(lambda: self.write_number(self.buttonpoint.text()))
        self.buttonadd.clicked.connect(lambda: self.write_number(self.buttonadd.text()))
        self.buttonsub.clicked.connect(lambda: self.write_number(self.buttonsub.text()))
        self.buttondiv.clicked.connect(lambda: self.write_number(self.buttondiv.text()))
        self.buttonmult.clicked.connect(lambda: self.write_number(self.buttonmult.text()))
        self.buttonprocent.clicked.connect(lambda: self.write_number(self.buttonprocent.text()))
        self.buttonequally.clicked.connect(self.answer)
        self.buttonc.clicked.connect(self.clean)
        self.buttonbackspace.clicked.connect(self.del_last)



    def write_number(self, number):
        if self.input_data.text() == '0':
            self.input_data.setText(number)
        else:
            self.input_data.setText(self.input_data.text() + number)


    def del_last(self):
        text = self.input_data.text()
        if not text:
            self.input_data.setText('0')
        else:
            text = self.input_data.text()[:-1]
            self.input_data.setText(text)

    def clean(self):
        self.input_data.setText('0')

    def answer(self):
        result = eval(self.input_data.text())
        self.input_data.setText(str(result))



if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

当我试图得到响应时,程序就崩溃了。

在此处输入图像描述

python
  • 1 个回答
  • 10 Views
Martin Hope
Захар Уляшов
Asked: 2022-08-23 05:10:11 +0000 UTC

从 QLineEdit 中删除最后一个字符

  • 1

我希望在触发函数时从 QLineEdit 中删除最后一个字符,但我不知道该怎么做

这是代码:

警告:当 pyuic5 再次运行时,对该文件所做的任何手动更改都将丢失。
除非您知道自己在做什么,否则不要编辑此文件。

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(320, 510)
        MainWindow.setMinimumSize(QtCore.QSize(320, 460))
        MainWindow.setMaximumSize(QtCore.QSize(320, 510))
        MainWindow.setStyleSheet("")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.input_data = QtWidgets.QLineEdit(self.centralwidget)
        self.input_data.setGeometry(QtCore.QRect(0, 0, 321, 141))
        font = QtGui.QFont()
        font.setPointSize(25)
        self.input_data.setFont(font)
        self.input_data.setStyleSheet("background-color: rgb(164, 218, 158);\n"
"color: #ffffff;\n"
"border: none;")
        self.input_data.setText("")
        self.input_data.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.input_data.setObjectName("input_data")
        self.button7 = QtWidgets.QPushButton(self.centralwidget)
        self.button7.setGeometry(QtCore.QRect(0, 140, 81, 81))
        self.button7.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button7.setFont(font)
        self.button7.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}\n"
"")
        self.button7.setObjectName("button7")
        self.button8 = QtWidgets.QPushButton(self.centralwidget)
        self.button8.setGeometry(QtCore.QRect(80, 140, 81, 81))
        self.button8.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button8.setFont(font)
        self.button8.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button8.setObjectName("button8")
        self.button9 = QtWidgets.QPushButton(self.centralwidget)
        self.button9.setGeometry(QtCore.QRect(160, 140, 81, 81))
        self.button9.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button9.setFont(font)
        self.button9.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button9.setObjectName("button9")
        self.button4 = QtWidgets.QPushButton(self.centralwidget)
        self.button4.setGeometry(QtCore.QRect(0, 220, 81, 81))
        self.button4.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button4.setFont(font)
        self.button4.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button4.setObjectName("button4")
        self.button5 = QtWidgets.QPushButton(self.centralwidget)
        self.button5.setGeometry(QtCore.QRect(80, 220, 81, 81))
        self.button5.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button5.setFont(font)
        self.button5.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button5.setObjectName("button5")
        self.button6 = QtWidgets.QPushButton(self.centralwidget)
        self.button6.setGeometry(QtCore.QRect(160, 220, 81, 81))
        self.button6.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button6.setFont(font)
        self.button6.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button6.setObjectName("button6")
        self.buttonpoint = QtWidgets.QPushButton(self.centralwidget)
        self.buttonpoint.setGeometry(QtCore.QRect(0, 380, 81, 81))
        self.buttonpoint.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonpoint.setFont(font)
        self.buttonpoint.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.buttonpoint.setObjectName("buttonpoint")
        self.button0 = QtWidgets.QPushButton(self.centralwidget)
        self.button0.setGeometry(QtCore.QRect(80, 380, 81, 81))
        self.button0.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button0.setFont(font)
        self.button0.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button0.setObjectName("button0")
        self.buttonc = QtWidgets.QPushButton(self.centralwidget)
        self.buttonc.setGeometry(QtCore.QRect(160, 380, 81, 81))
        self.buttonc.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonc.setFont(font)
        self.buttonc.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.buttonc.setObjectName("buttonc")
        self.button1 = QtWidgets.QPushButton(self.centralwidget)
        self.button1.setGeometry(QtCore.QRect(0, 300, 81, 81))
        self.button1.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button1.setFont(font)
        self.button1.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button1.setObjectName("button1")
        self.button2 = QtWidgets.QPushButton(self.centralwidget)
        self.button2.setGeometry(QtCore.QRect(80, 300, 81, 81))
        self.button2.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button2.setFont(font)
        self.button2.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button2.setObjectName("button2")
        self.button3 = QtWidgets.QPushButton(self.centralwidget)
        self.button3.setGeometry(QtCore.QRect(160, 300, 81, 81))
        self.button3.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.button3.setFont(font)
        self.button3.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(119, 204, 136);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.button3.setObjectName("button3")
        self.buttonsub = QtWidgets.QPushButton(self.centralwidget)
        self.buttonsub.setGeometry(QtCore.QRect(240, 300, 81, 81))
        self.buttonsub.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonsub.setFont(font)
        self.buttonsub.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(67, 187, 116);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.buttonsub.setObjectName("buttonsub")
        self.buttondiv = QtWidgets.QPushButton(self.centralwidget)
        self.buttondiv.setGeometry(QtCore.QRect(240, 220, 81, 81))
        self.buttondiv.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttondiv.setFont(font)
        self.buttondiv.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(67, 187, 116);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.buttondiv.setObjectName("buttondiv")
        self.buttonmult = QtWidgets.QPushButton(self.centralwidget)
        self.buttonmult.setGeometry(QtCore.QRect(240, 140, 81, 81))
        self.buttonmult.setMaximumSize(QtCore.QSize(81, 81))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonmult.setFont(font)
        self.buttonmult.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(67, 187, 116);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.buttonmult.setObjectName("buttonmult")
        self.buttonadd = QtWidgets.QPushButton(self.centralwidget)
        self.buttonadd.setGeometry(QtCore.QRect(240, 380, 81, 81))
        self.buttonadd.setMaximumSize(QtCore.QSize(81, 162))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonadd.setFont(font)
        self.buttonadd.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(67, 187, 116);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.buttonadd.setObjectName("buttonadd")
        self.buttonequally = QtWidgets.QPushButton(self.centralwidget)
        self.buttonequally.setGeometry(QtCore.QRect(0, 460, 321, 50))
        self.buttonequally.setMinimumSize(QtCore.QSize(0, 50))
        self.buttonequally.setMaximumSize(QtCore.QSize(500, 0))
        font = QtGui.QFont()
        font.setPointSize(20)
        self.buttonequally.setFont(font)
        self.buttonequally.setStyleSheet("QPushButton {\n"
"    color: #ffffff;\n"
"    background-color: rgb(67, 187, 116);\n"
"    border-radius: 0px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"    background-color: rgb(59, 185, 121);\n"
"}")
        self.buttonequally.setObjectName("buttonequally")
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)


        self.get_data()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.button7.setText(_translate("MainWindow", "7"))
        self.button8.setText(_translate("MainWindow", "8"))
        self.button9.setText(_translate("MainWindow", "9"))
        self.button4.setText(_translate("MainWindow", "4"))
        self.button5.setText(_translate("MainWindow", "5"))
        self.button6.setText(_translate("MainWindow", "6"))
        self.buttonpoint.setText(_translate("MainWindow", "."))
        self.button0.setText(_translate("MainWindow", "0"))
        self.buttonc.setText(_translate("MainWindow", "с"))
        self.button1.setText(_translate("MainWindow", "1"))
        self.button2.setText(_translate("MainWindow", "2"))
        self.button3.setText(_translate("MainWindow", "3"))
        self.buttonsub.setText(_translate("MainWindow", "-"))
        self.buttondiv.setText(_translate("MainWindow", "/"))
        self.buttonmult.setText(_translate("MainWindow", "*"))
        self.buttonadd.setText(_translate("MainWindow", "+"))
        self.buttonequally.setText(_translate("MainWindow", "="))

    def get_data(self):
        self.button0.clicked.connect(lambda: self.write_number(self.button0.text()))
        self.button1.clicked.connect(lambda: self.write_number(self.button1.text()))
        self.button2.clicked.connect(lambda: self.write_number(self.button2.text()))
        self.button3.clicked.connect(lambda: self.write_number(self.button3.text()))
        self.button4.clicked.connect(lambda: self.write_number(self.button4.text()))
        self.button5.clicked.connect(lambda: self.write_number(self.button5.text()))
        self.button6.clicked.connect(lambda: self.write_number(self.button6.text()))
        self.button7.clicked.connect(lambda: self.write_number(self.button7.text()))
        self.button8.clicked.connect(lambda: self.write_number(self.button8.text()))
        self.button9.clicked.connect(lambda: self.write_number(self.button9.text()))
        self.buttonadd.clicked.connect(lambda: self.write_number(self.buttonadd.text()))
        self.buttondiv.clicked.connect(lambda: self.write_number(self.buttondiv.text()))
        self.buttonsub.clicked.connect(lambda: self.write_number(self.buttonsub.text()))
        self.buttonmult.clicked.connect(lambda: self.write_number(self.buttonmult.text()))
        self.buttonequally.clicked.connect(self.rep())
        self.buttonpoint.clicked.connect(lambda: self.write_number(self.buttonpoint.text()))
        self.buttonc.clicked.connect(self.clean)



    def write_number(self, number):
        self.input_data.setText(self.input_data.text() + number)

    def clean(self):
        self.input_data.setText('')



if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
python
  • 1 个回答
  • 10 Views
Martin Hope
Захар Уляшов
Asked: 2022-08-22 02:46:26 +0000 UTC

按钮悬停动画(Qt 设计器)

  • 2

在此处输入图像描述

我想这样做,当我将鼠标悬停在按钮上时,它的背景会发生变化,但是当我没有安装transition任何东西时,动画会以相同的速度发生。

请告知如何做到这一点。

python
  • 1 个回答
  • 10 Views
Martin Hope
Захар Уляшов
Asked: 2022-08-20 19:34:21 +0000 UTC

编译 PyQt5 程序后图像不显示

  • 0

在 PyQt5 上编译程序后,程序中不显示图像,但是当我运行 python 文件时,一切正常。申请代码:

import sys
from PyQt5 import QtWidgets, uic


class MainApp(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi("design.ui", self)
        self.answer.clicked.connect(self.get_data)

    def get_data(self):
        # получение данных из формы
        heigth = float(self.input_heigth.text())
        weigth = float(self.input_weigth.text())
        heigth = heigth ** 2
        bmi = weigth / heigth
        if bmi >= 40:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI: {bmi}, у вас ожирение третьей степени!')
        if bmi > 35 and bmi < 39.99:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас ожирение второй степени!')
        if bmi > 30 and bmi < 34.99:
            self.input_weigth_2.setStyleSheet("color: #FF0000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас ожирение первой степени!')
        if bmi > 25 and bmi < 29.99:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас избыточная масса тела!')
        if bmi > 18.5 and bmi < 24.99:
            self.input_weigth_2.setStyleSheet("color: #008000;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, ваш вес в норме')
        if bmi > 16.5 and bmi < 18.49:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас дефицит массы тела!')
        if bmi < 16:
            self.input_weigth_2.setStyleSheet("color: #FFFF00;")
            self.input_weigth_2.setText(f'Ваш BMI {bmi}, у вас выраженный дефицит массы тела!')


if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    w = MainApp()
    w.show()
    sys.exit(app.exec_())

.ui 文件代码

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="minimumSize">
   <size>
    <width>0</width>
    <height>0</height>
   </size>
  </property>
  <property name="maximumSize">
   <size>
    <width>800</width>
    <height>600</height>
   </size>
  </property>
  <property name="contextMenuPolicy">
   <enum>Qt::NoContextMenu</enum>
  </property>
  <property name="acceptDrops">
   <bool>false</bool>
  </property>
  <property name="windowTitle">
   <string>Вычисление BMI</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="background">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
      <width>801</width>
      <height>601</height>
     </rect>
    </property>
    <property name="text">
     <string/>
    </property>
    <property name="pixmap">
     <pixmap>background.png</pixmap>
    </property>
   </widget>
   <widget class="QLabel" name="heigth">
    <property name="geometry">
     <rect>
      <x>290</x>
      <y>140</y>
      <width>401</width>
      <height>61</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>17</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);</string>
    </property>
    <property name="text">
     <string>Введите свой рост:</string>
    </property>
   </widget>
   <widget class="QLabel" name="main_text">
    <property name="geometry">
     <rect>
      <x>210</x>
      <y>50</y>
      <width>391</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Myanmar Text</family>
      <pointsize>35</pointsize>
      <weight>50</weight>
      <italic>false</italic>
      <bold>false</bold>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);
font: 35pt &quot;Myanmar Text&quot;;</string>
    </property>
    <property name="text">
     <string>Вычисление BMI</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="input_heigth">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>200</y>
      <width>331</width>
      <height>41</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>13</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: black;
border-radius: 20px;                     /* &lt;----  20px  */ 
border: 2px solid #094065;
text-align: center;</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QLabel" name="weigth">
    <property name="geometry">
     <rect>
      <x>290</x>
      <y>250</y>
      <width>401</width>
      <height>61</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>17</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);</string>
    </property>
    <property name="text">
     <string>Введите свой вес:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="input_weigth">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>310</y>
      <width>331</width>
      <height>41</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>13</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">
border-radius: 20px;                     /* &lt;----  20px  */ 
border: 2px solid #094065;</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QPushButton" name="answer">
    <property name="geometry">
     <rect>
      <x>320</x>
      <y>380</y>
      <width>161</width>
      <height>42</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>14</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>PointingHandCursor</cursorShape>
    </property>
    <property name="autoFillBackground">
     <bool>false</bool>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);
background-color: rgb(120, 183, 140);
border-radius: 20px;                     /* &lt;----  20px  */ 
border: 2px solid #094065;
transition: 1s;
hover {
    
    background-color: rgb(6, 53, 79);
}

button:active, button:focus {
  outline: none !important;
}
button::-moz-focus-inner {
  border: 0 !important;
}</string>
    </property>
    <property name="text">
     <string>Узнать BMI</string>
    </property>
    <property name="autoRepeat">
     <bool>false</bool>
    </property>
   </widget>
   <widget class="Line" name="line">
    <property name="geometry">
     <rect>
      <x>180</x>
      <y>90</y>
      <width>431</width>
      <height>31</height>
     </rect>
    </property>
    <property name="orientation">
     <enum>Qt::Horizontal</enum>
    </property>
   </widget>
   <widget class="QLabel" name="input_weigth_2">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>460</y>
      <width>651</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>13</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: #ffffff;</string>
    </property>
    <property name="text">
     <string/>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

我也尝试将 .ui 代码转换为 .py 代码,但没有帮助

程序目录: 在此处输入图像描述

python
  • 1 个回答
  • 10 Views
Martin Hope
Захар Уляшов
Asked: 2022-08-20 04:05:07 +0000 UTC

如何在 Qt Designer 中圆角按钮的边缘

  • 1

无法在Qt Designer中舍入按钮和输入字段。我已经尝试写入border-radius样式文件,但是没有帮助,而且我不知道更多的方法,我不想通过代码来做。

在此处输入图像描述

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="minimumSize">
   <size>
    <width>0</width>
    <height>0</height>
   </size>
  </property>
  <property name="maximumSize">
   <size>
    <width>800</width>
    <height>600</height>
   </size>
  </property>
  <property name="contextMenuPolicy">
   <enum>Qt::NoContextMenu</enum>
  </property>
  <property name="acceptDrops">
   <bool>false</bool>
  </property>
  <property name="windowTitle">
   <string>Вычисление BMI</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="background">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
      <width>801</width>
      <height>601</height>
     </rect>
    </property>
    <property name="text">
     <string/>
    </property>
    <property name="pixmap">
     <pixmap>background.png</pixmap>
    </property>
   </widget>
   <widget class="QLabel" name="heigth">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>110</y>
      <width>401</width>
      <height>61</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>17</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);</string>
    </property>
    <property name="text">
     <string>Введите свой рост:</string>
    </property>
   </widget>
   <widget class="QLabel" name="main_text">
    <property name="geometry">
     <rect>
      <x>210</x>
      <y>50</y>
      <width>391</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Myanmar Text</family>
      <pointsize>35</pointsize>
      <weight>50</weight>
      <italic>false</italic>
      <bold>false</bold>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);
font: 35pt &quot;Myanmar Text&quot;;</string>
    </property>
    <property name="text">
     <string>Вычисление BMI</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="input_heigth">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>170</y>
      <width>331</width>
      <height>31</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border-radius: 100;</string>
    </property>
   </widget>
   <widget class="QLabel" name="weigth">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>240</y>
      <width>401</width>
      <height>61</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>17</pointsize>
     </font>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);</string>
    </property>
    <property name="text">
     <string>Введите свой вес:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="input_weigth">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>300</y>
      <width>331</width>
      <height>31</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="answer">
    <property name="geometry">
     <rect>
      <x>290</x>
      <y>370</y>
      <width>211</width>
      <height>41</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>14</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>PointingHandCursor</cursorShape>
    </property>
    <property name="autoFillBackground">
     <bool>false</bool>
    </property>
    <property name="styleSheet">
     <string notr="true">color: rgb(255, 255, 255);
background-color: rgb(120, 183, 140);
border-radius: 25px;
border: 2px solid #094065;</string>
    </property>
    <property name="text">
     <string>Узнать BMI</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="input_weigth_2">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>460</y>
      <width>331</width>
      <height>31</height>
     </rect>
    </property>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>
python
  • 1 个回答
  • 10 Views
Martin Hope
Захар Уляшов
Asked: 2022-08-03 04:39:37 +0000 UTC

Python 机器人无法启动

  • 0

问题是机器人启动,但程序不启动,程序启动,但机器人不启动

编码:

#импорт библиотек
from tkinter import *
import discord
from discord.ext import commands

#содание главного окна
root = Tk()
root.geometry('400x500')
root.resizable(width=False, height=False)

#создание бота
bot = commands.Bot(command_prefix='$')
client = discord.Client()

#проверка готовности бота
@bot.listen('on_ready')
async def ready():
    print('Бот успешно запущен!')

#фукнкции бота
@bot.command()
async def hi(ctx):
    ctx.send(f'Hello, {ctx.author.mention}')


#графические элементы программы
hello = Button(text='Поздороваться с пользователем', command=hi)
hello.place(x='10', y='20')



#запуск бота и цикла программы
root.mainloop()
bot.run('OTQxOTczODI0MTU5NzQ0MDIw.YgdvfA.2-JQ3WgUO01J3ikuyzDfx6IeyCQ')

我想将graph.interface连接到机器人,告诉我如何解决这个问题

python
  • 1 个回答
  • 10 Views
Martin Hope
Захар Уляшов
Asked: 2022-07-23 01:44:43 +0000 UTC

Bot 不会禁止会员

  • 0

用python写了一个机器人。我做了它来禁止参与者,但不幸的是它只是给出了一个错误:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

资源:

#import need library and module
import discord
from discord.ext import commands

#defining the prefix to be used to call the function
bot = commands.Bot(command_prefix='$')
client = discord.Client()


@bot.command()
async def ban(ctx, member: commands.MemberConverter):
    await ctx.guild.ban(member)


#called the bot
bot.run('')

该机器人拥有所有权利

python
  • 1 个回答
  • 10 Views
Martin Hope
Захар Уляшов
Asked: 2022-07-15 12:46:53 +0000 UTC

discord bot没有响应命令[关闭]

  • -2
关闭 这个问题是题外话。目前不接受回复。

寻求调试帮助的问题(“为什么这段代码不起作用? ”)应该包括期望的行为、具体的问题或错误,以及在问题中重现它的最少代码。没有明确描述问题的问题对其他访问者毫无用处。请参阅如何创建一个最小的、独立的和可重现的示例。

7 个月前关闭。

改进问题

告诉我如何解决这个问题?启动机器人时,它应该返回书面消息,但不返回:

import discord
from discord.ext import commands

client = discord.Client()

bot = commands.Bot(command_prefix='$')


@client.event
async def on_ready():
    print('Бот запущен')
    

@bot.command()
async def foo(ctx, arg):
    await ctx.send(arg)

    
python
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5