RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

5478512's questions

Martin Hope
5478512
Asked: 2020-03-22 00:59:21 +0000 UTC

如何从python中的不同文件夹导入文件?

  • 0

主文件有一个路径:С:\\myapp\app.py 工作还需要第二个文件:С:\\myapp\folder\additional_file.py

如何将文件additional_file.py导入app.py?

python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-03-14 00:51:24 +0000 UTC

如何在 QScrollArea 中滚动小部件?

  • 2

我尝试添加QVBoxLayout - QScrollArea和QScrollBar。
如layout添加它们的小部件所示player(2 件)。

滚动时,小部件成倍增加。如果它很简单,那么你需要做QScrollAreaand QScrollBar,当滚动 which 时,它们会滚动player'ы。

它应该看起来如何,大约(小部件移出):

在此处输入图像描述

我得到什么:

在此处输入图像描述

这是部分代码: Main.py

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
import sys, os

import player
class Main(QtWidgets.QWidget): 
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setFixedSize(750, 560)

        self.p1 = player.player_1()
        
        self.lay = QHBoxLayout(self)
        self.lay.setContentsMargins(0,0,0,0)
        
        self.scroll_area = QtWidgets.QScrollArea(self)                                        # 2
        self.scroll_area.setLayout(self.lay)
        self.scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.scrollbar = QtWidgets.QScrollBar(Qt.Horizontal, self)                            # 3
        self.scrollbar.setMaximum(250)

        self.scrollbar.valueChanged.connect(self.sync_func)                         # 4

        self.v_layout = QtWidgets.QVBoxLayout(self)
        self.v_layout.addWidget(self.scroll_area)
        self.v_layout.addWidget(self.scrollbar)

    def sync_func(self):
        self.scroll_area.horizontalScrollBar().setValue(self.scrollbar.value() * 1)

        self.lay.addWidget(Sttings())
        self.lay.addWidget(player.player_1())
        self.lay.addWidget(player.player_1())


        self.transition()

    def transition(self):

        player.reputation_perem = player.reputation_perem + (player.reputation_perem / 100 * 5)
        player.money_perem = player.money_perem + player.income_perem

       #reputation_perem_2 = reputation_perem_2 + (reputation_perem_2 / 100 * 5)
       #income_perem_2 = income_perem_old_2 / 100 * (100 - (100 - reputation_perem_2))
       #money_perem_2 = money_perem_2 + income_perem_2
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)                        
    w = Main()
    w.show()

    file = QtCore.QFile("C:/for cheacher/3_mate_files/dark.qss")                              
    file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text)
    stream = QtCore.QTextStream(file)
    app.setStyleSheet(stream.readAll())

    sys.exit(app.exec_())

播放器.py:

money_perem = 0
income_perem_old = 500
income_perem = 0
credit_perem = 0
reputation_perem = 20
class player_1(QtWidgets.QWidget): 
    def __init__(self, parent=None):
        global money_perem, credit_perem, reputation_perem, income_perem, income_perem_old
        super(player_1, self).__init__(parent)
    
        self.setFixedSize(350, 550)
    
    #   изображение
        self.Label_ing = QLabel('', self)
        self.img = QtGui.QPixmap('C:/py/Monopolya/polzovatel_1.png')
        self.Label_ing.setPixmap(self.img)
    
        self.Label_ing.move(75, 20)
    
    
    #   манипуляции
    
    #   Валюта
        self.PB_money = QPushButton('Валюта ₽', self)
        self.PB_money.move(15, 260)
        self.PB_money.resize(150, 25)
        self.PB_money.setStyleSheet('font: 13pt \'Arial Black\'')
    
        self.PB_money.clicked.connect(self.money_func)
    
    #   Репутация
        self.PB_reputation = QPushButton('Репутация ⓇⓅ', self)
        self.PB_reputation.move(185, 260)
        self.PB_reputation.resize(150, 25)
        self.PB_reputation.setStyleSheet('font: 13pt \'Arial Black\'')
    
        self.PB_reputation.clicked.connect(self.reputation_func)
    
    #   Кредит
        self.PB_credit = QPushButton("Кредит", self)
        self.PB_credit.move(15, 300)
        self.PB_credit.resize(150, 25)
        self.PB_credit.setStyleSheet('font: 13pt \'Arial Black\'')
    
        self.PB_credit.clicked.connect(self.credit_func)
    #   Доход
        self.PB_income = QPushButton('Доход', self)
        self.PB_income.move(185, 300)
        self.PB_income.resize(150, 25)
        self.PB_income.setStyleSheet('font: 13pt \'Arial Black\'')
    
        self.PB_income.clicked.connect(self.income_func)
    
     #   информация
    
        self.Label_Money = QLabel(self)
        self.Label_Money.move(50, 350)
        self.Label_Money.resize(400, 25)
        self.Label_Money.setStyleSheet("font: 15pt \'Arial Black\'")
    
        self.Label_reputation = QLabel(self)
        self.Label_reputation.move(50, 400)
        self.Label_reputation.resize(400, 25)
        self.Label_reputation.setStyleSheet("font: 15pt \'Arial Black\'")
    
        self.Label_income = QLabel(self)
        self.Label_income.move(50, 450)
        self.Label_income.resize(400, 25)
        self.Label_income.setStyleSheet("font: 15pt \'Arial Black\'")
    
        self.Label_credit = QLabel(self)
        self.Label_credit.move(50, 500)
        self.Label_credit.resize(400, 25)
        self.Label_credit.setStyleSheet("font: 15pt \'Arial Black\'")
    
        self.t = QtCore.QTimer(interval=100)
        self.t.timeout.connect(self.update_info)
        self.t.start()
    
    def update_info(self):
        global money_perem, reputation_perem, income_perem, credit_perem, income_perem_old
    
        income_perem = income_perem_old / 100 * (100 - (100 - reputation_perem))
    
        self.Label_Money.setText('Деньги: ' + str(money_perem / 1000000) + ' ' + "млн ₽")
        self.Label_reputation.setText('Репутация: ' + str(reputation_perem) + ' ' + 'ⓇⓅ')
        self.Label_income.setText('Доход: ' + str(income_perem / 1000) + ' ' + '(' + str(income_perem_old / 1000) + ')' + ' тыс ₽')
        self.Label_credit.setText('Кредит: ' + str(credit_perem / 1000000) + ' ' + 'млн ₽')
    
    
    
    def credit_func(self):
        self.cr = credit()
        self.cr.show()
    def money_func(self):
        self.m = money()
        self.m.show()
    def reputation_func(self):
        self.rep = reputation()
        self.rep.show()
    def income_func(self):
        self.incom = income()
        self.incom.show()
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)                        
    file = QtCore.QFile("C:/for cheacher/3_mate_files/dark.qss")                              
    file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text)
    stream = QtCore.QTextStream(file)
    app.setStyleSheet(stream.readAll())

    w = player_1()
    w.show()

    sys.exit(app.exec_())
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-02-28 00:56:40 +0000 UTC

如何从yandex磁盘下载文件

  • 4

有一个文件:https ://yadi.sk/d/xsjJ3dEqb4pvlQ (它是打开的)我怎样才能下载它?不需要授权等。

python
  • 2 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-02-12 00:17:28 +0000 UTC

应用程序关闭时如何打开对话框?

  • 1

关闭程序时如何询问是否关闭程序?

代码示例:

from PyQt5 import QtCore, QtGui, QtWidgets
import sys

class Main(object):
    def __init__(self):
        super(Main, self).__init__()
        self.setFixedSize(423, 293)

        self.lineEdit1 = QtWidgets.QLineEdit("", self)
        self.lineEdit1.resize(321, 51)
        self.lineEdit1.move(50, 80)

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)                        
    w = Main()
    w.show()
    
    sys.exit(app.exec_())
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-02-07 15:57:00 +0000 UTC

如何更改 QLabel 中的文本颜色?

  • 2

有没有QLabel办法改变文字颜色RGB?

self.Label = QtWidgets.QLabel("", self)
self.Label.move(50, 30)
self.Label.resize(421, 41)
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-01-21 00:02:06 +0000 UTC

如何调整 QCheckBox 的大小?

  • 2

我怎样才能改变这部分checkbox?

self.CB_30min = QCheckBox("15 мин", self)
self.CB_30min.move(310, 110)
self.CB_30min.resize(91, 31)

在此处输入图像描述

python
  • 3 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-01-08 21:12:34 +0000 UTC

如何判断窗户是否打开?

  • 2

有窗户main和 win如果窗口打开,如果它关闭,则win写入控制台。"окно открыто""окно закрыто"

怎么做?

代码示例:

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_main(object):
    def setupUi(self, main):
        main.setObjectName("main")
        main.resize(400, 300)
        self.label = QtWidgets.QLabel(main)
        self.label.setGeometry(QtCore.QRect(20, 20, 111, 41))
        self.label.setStyleSheet("font: 87 16pt \"Arial Black\";")
        self.label.setObjectName("label")
        self.pushButton_1 = QtWidgets.QPushButton(main)
        self.pushButton_1.setGeometry(QtCore.QRect(10, 10, 50, 31))
        self.pushButton_1.setStyleSheet("font: 87 14pt \"Arial Black\";")
        self.pushButton_1.setObjectName("pushButton")
        self.retranslateUi(main)
        QtCore.QMetaObject.connectSlotsByName(main)

    def retranslateUi(self, main):
        _translate = QtCore.QCoreApplication.translate
        main.setWindowTitle(_translate("main", "Form"))
        self.label.setText(_translate("main", "main"))
        self.pushButton_1.setText(_translate("main", "нажать"))

class Ui_window_1(object):
    def setupUi(self, window_1):
        window_1.setObjectName("window_1")
        window_1.resize(400, 300)
        self.label = QtWidgets.QLabel(window_1)
        self.label.setGeometry(QtCore.QRect(20, 20, 111, 41))
        self.label.setStyleSheet("font: 87 16pt \"Arial Black\";")
        self.label.setObjectName("label")

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

    def retranslateUi(self, window_1):
        _translate = QtCore.QCoreApplication.translate
        window_1.setWindowTitle(_translate("window_1", "Form"))
        self.label.setText(_translate("window_1", "window_1"))

class Win(QtWidgets.QWidget, Ui_window_1):
    def __init__(self, parent=None):
        super(Win, self).__init__(parent)

class Main(QtWidgets.QWidget, Ui_main):
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
    b = #определение открыто ли окно или нет
    if b == True:
        print("Окно открыто")
    else:
        print("Окно закрыто")
        self.setupUi(self)
        self.pushButton_1.clicked.connect(self.Win_f)
    def Win_f(self):
        self.wmain = Win()
        self.wmain.show()
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv) 
    w = Main()
    w.show()

    sys.exit(app.exec_())
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-01-07 22:28:18 +0000 UTC

为什么会出现对象不可调用错误?

  • 0

再次调用 och 函数时,报错:

    self.och()
    TypeError: 'Myoch' object is not callable

这是代码的一部分:

    def opr(self):
    path = File_location + "1_classes/" + self.lineEdit1.text() + '.txt'
    try:
        file = open(path)
    except IOError as e:
        self.och()
    else:
        self.uch()

och函数:

    def och(self):
        self.och = Myoch()
        self.och.show()  
python-3.x
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-31 20:36:43 +0000 UTC

如何循环一个函数?

  • 1

我有一个程序:

import time

from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1110, 671)
        self.la_non = QtWidgets.QLabel(Form)
        self.la_non.setGeometry(QtCore.QRect(10, 10, 1091, 71))
        self.la_non.setStyleSheet("font: 48pt \"Molot\";")
        self.la_non.setObjectName("la_non")
        self.label_lime = QtWidgets.QLabel(Form)
        self.label_lime.setGeometry(QtCore.QRect(20, 150, 1071, 491))
        self.label_lime.setStyleSheet("font: 55pt \"Molot\";")
        self.label_lime.setObjectName("label_lime")

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

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.la_non.setText(_translate("Form", "1234"))



class Main(QtWidgets.QWidget, Ui_Form): 
    def __init__(self, parent=None):
        super(Main, self).__init__(parent) 

        self.setupUi(self)
    def time(self):

        import time
        time = str(time.strftime("%X"))
        hour, minute, second = time.split(':')
        self.label_lime.setText(str(23 - int(hour)) + " " + "часов" + " " + str(59 - int(minute)) + " " +"минут" + " " + str(60 - int(second)) + " " + "секунд")
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)                        
    w = Main()
    w.show()
    sys.exit(app.exec_())

你需要循环函数时间。

python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-28 02:20:47 +0000 UTC

如何检测文本从哪个字符超出标签?

  • 2

如何确定文本超出范围的字符label?

从15字符开始,文本走出了窗口。

如何移动一条线?

例子:

а б в г д е е е д д  д  д  д  о  о  о  о  о  к  к  к  к 
1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20 21 22 23 и т.д
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-26 19:10:57 +0000 UTC

如何在pyqt5中获取当前窗口大小?

  • 2

如何在调整窗口大小时更改其中的小部件的大小。

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1000, 834)
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(200, 510, 541, 121))
        self.pushButton.setObjectName("pushButton")
        self.lineEdit = QtWidgets.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(230, 100, 481, 201))
        self.lineEdit.setObjectName("lineEdit")

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

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "PushButton"))

class Main(QtWidgets.QWidget, Ui_Form): 
    def __init__(self, parent=None):
    super(Main, self).__init__(parent)        
    while True:
        width = "определение ширины"
        height = "определение высоты"

        x = width - 1000
        y = height - 834

        Form.resize(1000 + x, 834 + y)
        self.pushButton.setGeometry(541 + x, 121 + y)
        self.lineEdit.setGeometry(481 + x, 201 + y)
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-25 15:53:34 +0000 UTC

为什么chromedriver看不到它?

  • 0
from selenium import webdriver
def main():
    driver = webdriver.Chrome()
    url = "https://vk.com/"
    driver.get(url)
    login = driver.find_element_by_name_name("email")
    login.clear()
    login.send_keys("123")
    pswd = driver.find_element_by_name_name('pass')
    pswd.send_keys("123")
    but_log = driver.find_element_by_class_name("index_login_button")
    but_log.click()
main()

代码抛出错误

      $ C:\py\piramida.py
  Traceback (most recent call last):
    File "C:\Users\Danila\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
      stdin=PIPE)
    File "C:\Users\Danila\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
      restore_signals, start_new_session)
    File "C:\Users\Danila\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
      startupinfo)
  FileNotFoundError: [WinError 2] Не удается найти указанный файл

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "C:\py\piramida.py", line 13, in <module>
      main()
    File "C:\py\piramida.py", line 3, in main
      driver = webdriver.Chrome()
    File "C:\Users\Danila\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
      self.service.start()
    File "C:\Users\Danila\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
      os.path.basename(self.path), self.start_error_message)
  selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-22 21:03:19 +0000 UTC

如何判断checkBox是否被激活?

  • 3

如何确定CheckBox激活了什么?

比方说,如果它checkBox处于活动状态,则显示 1,如果它未处于活动状态,则显示 2。

怎么做?如果小部件上有“勾号”,我认为是活动的。

с = #определение состояния
if c == #есть "галочка":
   x = 5
elif c == #нет "галочки":
   x = 10
print(x)

#что-то не так
import subprocess
from PyQt5.QtWidgets import QApplication
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(959, 365)
        Form.setStyleSheet("")
        self.checkBox = QtWidgets.QCheckBox(Form)
        self.checkBox.setGeometry(QtCore.QRect(20, 230, 421, 41))
        self.checkBox.setObjectName("checkBox")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(23, 30, 441, 41))
        self.label.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(494, 20, 421, 61))
        self.label_2.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label_2.setObjectName("label_2")
        self.lineEdit = QtWidgets.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(20, 80, 421, 41))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(Form)
        self.lineEdit_2.setGeometry(QtCore.QRect(490, 80, 431, 41))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label_3 = QtWidgets.QLabel(Form)
        self.label_3.setGeometry(QtCore.QRect(25, 164, 421, 21))
        self.label_3.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(Form)
        self.label_4.setGeometry(QtCore.QRect(493, 160, 421, 31))
        self.label_4.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label_4.setObjectName("label_4")
        self.lineEdit_3 = QtWidgets.QLineEdit(Form)
        self.lineEdit_3.setGeometry(QtCore.QRect(21, 190, 421, 41))
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.lineEdit_4 = QtWidgets.QLineEdit(Form)
        self.lineEdit_4.setGeometry(QtCore.QRect(489, 190, 431, 41))
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(20, 280, 901, 51))
        self.pushButton.setStyleSheet("font: 87 26pt \"Arial Black\";")
        self.pushButton.setObjectName("pushButton")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
        self.checkBox.stateChanged.connect(
            lambda state=self.checkBox.isChecked(), no=1: self.selectBooks(state, no))

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.checkBox.setText(_translate("Form", "Использовать тот же путь"))
        self.label.setText(_translate("Form", "Введи путь до исходного файла"))
        self.label_2.setText(_translate("Form", "Введи название исходного файла"))
        self.label_3.setText(_translate("Form", "Введи путь до конечного файла"))
        self.label_4.setText(_translate("Form", "Введи название конечного файла"))
        self.pushButton.setText(_translate("Form", "Конвертировать"))




app = QApplication([])

class Main(QtWidgets.QWidget, Ui_Form): 
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)
        file = str(self.lineEdit.text()) + "/" + str(self.lineEdit_2)
        def selectBooks(self, toggle, no):
            if toggle == QtCore.Qt.Checked:
                print('toggle=`{}`, checked_{}'.format(toggle, no))
                if no == 1:
                    print('checked_{} -> галочка поставлена выполнилось действие'.format(no))
            else:
                print('toggle=`{}`, unchecked_{}'.format(toggle, no))

mw = Main()
mw.show()


app.exec()
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-21 22:21:26 +0000 UTC

为什么代码不运行?

  • 0
import subprocess

from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(959, 365)
        Form.setStyleSheet("")
        self.checkBox = QtWidgets.QCheckBox(Form)
        self.checkBox.setGeometry(QtCore.QRect(20, 230, 421, 41))
        self.checkBox.setObjectName("checkBox")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(23, 30, 441, 41))
        self.label.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(494, 20, 421, 61))
        self.label_2.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label_2.setObjectName("label_2")
        self.lineEdit = QtWidgets.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(20, 80, 421, 41))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(Form)
        self.lineEdit_2.setGeometry(QtCore.QRect(490, 80, 431, 41))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label_3 = QtWidgets.QLabel(Form)
        self.label_3.setGeometry(QtCore.QRect(25, 164, 421, 21))
        self.label_3.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(Form)
        self.label_4.setGeometry(QtCore.QRect(493, 160, 421, 31))
        self.label_4.setStyleSheet("font: 87 12pt \"Arial Black\";")
        self.label_4.setObjectName("label_4")
        self.lineEdit_3 = QtWidgets.QLineEdit(Form)
        self.lineEdit_3.setGeometry(QtCore.QRect(21, 190, 421, 41))
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.lineEdit_4 = QtWidgets.QLineEdit(Form)
        self.lineEdit_4.setGeometry(QtCore.QRect(489, 190, 431, 41))
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(20, 280, 901, 51))
        self.pushButton.setStyleSheet("font: 87 26pt \"Arial Black\";")
        self.pushButton.setObjectName("pushButton")

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

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.checkBox.setText(_translate("Form", "Использовать тот же путь"))
        self.label.setText(_translate("Form", "Введи путь до исходного файла"))
        self.label_2.setText(_translate("Form", "Введи название исходного файла"))
        self.label_3.setText(_translate("Form", "Введи путь до конечного файла"))
        self.label_4.setText(_translate("Form", "Введи название конечного файла"))
        self.pushButton.setText(_translate("Form", "Конвертировать"))

class Main(QtWidgets.QWidget, Ui_Form): 
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)
        file = self.lineEdit.Text() + "/" + self.lineEdit_2
        x = self.checkBox.isChecked()

界面应该打开了,但是打不开,怎么办?

python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-18 22:50:24 +0000 UTC

如何检查文件是否存在?[复制]

  • 0
这个问题已经在这里得到了回答:
如何检查文件是否存在? (6 个回答)
2年前关闭。

我尝试了两种方法:

一。

    f = path(file_location + '1_classes/' + self.lineEdit1.text() + '.txt')
    if f.is_file():
        self.uch()
        file.close()
    else:
        self.och()
        file.close()

2.

        try:
    file = open(file_location + "1_classes/" + self.lineEdit1.text() + '.txt')
    except IOError as e:
        self.och()
        file.close()
    else:
        self.uch()
        file.close()

两种方式都行不通。如有必要,我找到了文件的路径,如下所示:

file_location + '1_classes/' + self.lineEdit1.text() + '.txt'

路径形成正确,检查。
即使文件存在,代码也会打开一个报告错误的窗口。

python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-17 23:57:25 +0000 UTC

如果程序在 PyQt5 中有多个窗口,如何使用一个窗口?

  • 2

我有一个程序,其中有三个窗口。我不明白如何只使用一个窗口(显示文本,使用按钮)。

这是代码:main.py

from PyQt5 import QtCore, QtGui, QtWidgets

from ui_inst import Ui_Inst
from ui_uch import Ui_Uch                           

class Ui_Start(object):
    def setupUi(self, Ui_Start):
        Ui_Start.setObjectName("Ui_Start")
        Ui_Start.resize(443, 293)

        self.lineEdit1 = QtWidgets.QLineEdit(Ui_Start)
        self.lineEdit1.setGeometry(QtCore.QRect(50, 80, 321, 51))
        self.lineEdit1.setStyleSheet("")
        self.lineEdit1.setText("")
        self.lineEdit1.setObjectName("lineEdit")
        self.textEdit = QtWidgets.QTextEdit(Ui_Start)
        self.textEdit.setGeometry(QtCore.QRect(10, 30, 421, 41))
        self.textEdit.setObjectName("textEdit")
        self.pushButton_2 = QtWidgets.QPushButton(Ui_Start)
        self.pushButton_2.setGeometry(QtCore.QRect(150, 210, 141, 58))
        self.pushButton_2.setStyleSheet("font: 16pt \"Molot\";")
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton = QtWidgets.QPushButton(Ui_Start)
        self.pushButton.setGeometry(QtCore.QRect(50, 140, 321, 58))
        self.pushButton.setStyleSheet("font: 20pt \"Molot\";")
        self.pushButton.setObjectName("pushButton")

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

    def retranslateUi(self, Ui_Start):
        _translate = QtCore.QCoreApplication.translate
        Ui_Start.setWindowTitle(_translate("Ui_Start", "Ui_Start"))
        self.textEdit.setHtml(_translate("Ui_Start", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
        "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
        "p, li { white-space: pre-wrap; }\n"
        "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
        "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">Введите номер и букву класса:</span></p></body></html>"))
        self.pushButton_2.setText(_translate("Ui_Start", "инструкция"))
        self.pushButton.setText(_translate("Ui_Start", "Найти класс"))


class MyInst(QtWidgets.QWidget, Ui_Inst):
    def __init__(self, parent=None):
        super(MyInst, self).__init__(parent)
        self.setupUi(self)
class MyUch(QtWidgets.QWidget, Ui_Uch):
    def __init__(self, parent=None):
        super(MyUch, self).__init__(parent)
        self.setupUi(self)       


class Main(QtWidgets.QWidget, Ui_Start):
    def __init__(self, parent=None):
        super(Main, self).__init__(parent)
        self.setupUi(self)

        self.pushButton_2.clicked.connect(self.onClicked)
        self.pushButton.clicked.connect(self.uch)

    def onClicked(self):
        self.inst = MyInst()
        self.inst.show()
    def uch(self):
        self.uch = MyUch()
        self.uch.show()
        self.lineEdit2.setText("1")

    



StyleSheet = '''
QPushButton {
    font: bold italic 16pt 'Comic Sans MS';
    background-color: silver;
    width: 75px ;
    height: 50px;
    border: none;
    text-align: center;
}
QPushButton:hover {
    background: #C9C0BB; 
}            
QPushButton:pressed {
    background-color: blue;
}

'''


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)

    app.setStyleSheet(StyleSheet)                          

    file = QtCore.QFile("dark.qss")                                
    file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text)
    stream = QtCore.QTextStream(file)
    app.setStyleSheet(stream.readAll())

    w = Main()
    w.show()

    sys.exit(app.exec_())

ui_inst.py:

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Inst(object):
    def setupUi(self, Inst):
        Inst.setObjectName("Ui_Inst")
        Inst.resize(1111, 883)
        self.textEdit = QtWidgets.QTextEdit(Inst)                        
        self.textEdit.setGeometry(QtCore.QRect(0, 10, 1111, 41))
        self.textEdit.setObjectName("textEdit")
        self.text_inctru = QtWidgets.QTextEdit(Inst)
        self.text_inctru.setGeometry(QtCore.QRect(20, 60, 1071, 811))
        self.text_inctru.setObjectName("text_inctru")

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

    def retranslateUi(self, Inst):
        _translate = QtCore.QCoreApplication.translate
        Inst.setWindowTitle(_translate("Inst", "Inst"))
        self.textEdit.setHtml(_translate("Inst", "<!DOCTYPE HTML PUBLIC 
        \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC- 
        html40/strict.dtd\">\n"
        "<html><head><meta name=\"qrichtext\" content=\"1\" /><style 
        type=\"text/css\">\n"
        "p, li { white-space: pre-wrap; }\n"
        "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font- 
        size:8.25pt; font-weight:400; font-style:normal;\">\n"
        "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; 
        margin-left:0px; margin-right:0px; -qt-block-indent:0; text- 
        indent:0px;\"><span style=\" font-size:22pt;\">Инструкция</span></p> 
        </body></html>"))

ui_uch.py​​ ​​​:

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Uch(object):
    def setupUi(self, Uch):
        Uch.setObjectName("Uch")
        Uch.resize(718, 336)
        self.lineEdit = QtWidgets.QLineEdit(Uch)
        self.lineEdit.setGeometry(QtCore.QRect(60, 40, 611, 81))
        self.lineEdit.setStyleSheet("font: 20pt \"Molot\";")
        self.lineEdit.setObjectName("lineEdit1")
        self.pushButton = QtWidgets.QPushButton(Uch)
        self.pushButton.setGeometry(QtCore.QRect(190, 140, 341, 51))
        self.pushButton.setStyleSheet("font: 27pt \"Molot\";")
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(Uch)
        self.pushButton_2.setGeometry(QtCore.QRect(60, 222, 601, 61))
        self.pushButton_2.setStyleSheet("font: 45pt \"Molot\";")
        self.pushButton_2.setObjectName("pushButton_2")
        self.label = QtWidgets.QLabel(Uch)
        self.label.setGeometry(QtCore.QRect(70, 0, 601, 41))
        self.label.setStyleSheet("font: 25pt \"Molot\";")
        self.label.setObjectName("label")

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

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Uch", "Uch"))
        self.pushButton.setText(_translate("Uch", "Выбрать ученика"))
        self.pushButton_2.setText(_translate("Uch", "Задать вопрос"))
        self.label.setText(_translate("Uch", "Отвечает ученик:"))
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-16 19:20:55 +0000 UTC

如何在 PyQt5 中打开第二个窗口?

  • 3

我有两个窗户。

如何,当您单击窗口中的“指令”按钮时start,打开窗口inst?

开始(开始窗口):

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Start(object):
    def setupUi(self, Start):
        Start.setObjectName("Ui_Start")
        Start.resize(443, 293)
        Start.setStyleSheet("QPushButton:hover {backgroun-color: red}    \n"
"QPushButton:pressed {backgroun-color: blue\n"
"}\n"
"QPushButton{\n"
"    font: 45pt \"Molot\";\n"
"    backgroun-color: white;\n"
"    width: 75px ;\n"
"    height: 50px;\n"
"    font-size: 45px;\n"
"    font-weight: bold;\n"
"    bolder: none;\n"
"    text-align: center\n"
"}\n"
"\n"
"")
        self.lineEdit = QtWidgets.QLineEdit(Start)
        self.lineEdit.setGeometry(QtCore.QRect(50, 80, 321, 51))
        self.lineEdit.setStyleSheet("")
        self.lineEdit.setText("")
        self.lineEdit.setObjectName("lineEdit")
        self.textEdit = QtWidgets.QTextEdit(Start)
        self.textEdit.setGeometry(QtCore.QRect(10, 30, 421, 41))
        self.textEdit.setObjectName("textEdit")
        self.pushButton_2 = QtWidgets.QPushButton(Start)
        self.pushButton_2.setGeometry(QtCore.QRect(150, 210, 141, 58))
        self.pushButton_2.setStyleSheet("font: 16pt \"Molot\";")
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton = QtWidgets.QPushButton(Start)
        self.pushButton.setGeometry(QtCore.QRect(50, 140, 321, 58))
        self.pushButton.setObjectName("pushButton")

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

    def retranslateUi(self, v):
        _translate = QtCore.QCoreApplication.translate
        Start.setWindowTitle(_translate("Start", "Start"))
        self.textEdit.setHtml(_translate("Start", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:16pt;\">введите номер и букву класса класса :</span></p></body></html>"))
        self.pushButton_2.setText(_translate("Start", "инструкция"))
        self.pushButton.setText(_translate("Start", "1"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Start = QtWidgets.QWidget()
    ui = Ui_Start()
    ui.setupUi(Start)
    Start.show()
    sys.exit(app.exec_())

inst(指令):

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Inst(object):
    def setupUi(self, Inst):
        Inst.setObjectName("Ui_Inst")
        Inst.resize(1111, 883)
        self.textEdit = QtWidgets.QTextEdit(v)
        self.textEdit.setGeometry(QtCore.QRect(0, 10, 1111, 41))
        self.textEdit.setObjectName("textEdit")
        self.text_inctru = QtWidgets.QTextEdit(Inst)
        self.text_inctru.setGeometry(QtCore.QRect(20, 60, 1071, 811))
        self.text_inctru.setObjectName("text_inctru")

        self.retranslateUi(Inst)
        QtCore.QMetaObject.connectSlotsByName(v)

    def retranslateUi(self, Inst):
        _translate = QtCore.QCoreApplication.translate
        Inst.setWindowTitle(_translate("Inst", "Inst"))
        self.textEdit.setHtml(_translate("Inst", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:22pt;\">Инструкция</span></p></body></html>"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Inst = QtWidgets.QWidget()
    ui = Ui_Inst()
    ui.setupUi(Inst)
    Inst.show()
    sys.exit(app.exec_())
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-10 14:48:06 +0000 UTC

如何打开在 Qt Designer 中创建的第二个窗口?

  • 1

如何打开第二个窗口?

from PySide import QtCore, QtGui
import sys
from ui import Ui_Start
import time

app = QtGui.QApplication(sys.argv)


Start = QtGui.QWidget()
ui = Ui_Start()
ui.setupUi(Start)
Start.show()
def but_1():
   from ui import Ui_inst
   app = QtGui.QApplication(sys.argv)

   inst = QtGui.QWidget()
   ui_ins = Ui_inst()
   ui_ins.setupUi(inst)
   inst.show()
   ui_ins.textEdit.setText("12546")

   sys.exit(app.exec_())

   ui.pushButton_2.clicked.connect( but_1 )     

   sys.exit(app.exec_())
python
  • 1 个回答
  • 10 Views
Martin Hope
5478512
Asked: 2020-12-06 15:14:05 +0000 UTC

如何将所需的值写入变量?

  • 1

有一个代码:

from PySide import QtCore, QtGui
import sys
from ui import Ui_Form
import time
app = QtGui.QApplication(sys.argv)


Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
t = ""
#   функции
def but1():
    ui.lineEdit.setText(ui.lineEdit.text() + "1")
def but2():
    ui.lineEdit.setText(ui.lineEdit.text() + "2")   
def but3():
    ui.lineEdit.setText(ui.lineEdit.text() + "3")
def but4():
    ui.lineEdit.setText(ui.lineEdit.text() + "4")
def but5():
    ui.lineEdit.setText(ui.lineEdit.text() + "5")
def but6():
    ui.lineEdit.setText(ui.lineEdit.text() + "6")
def but7():
    ui.lineEdit.setText(ui.lineEdit.text() + "7")
def but8():
    ui.lineEdit.setText(ui.lineEdit.text() + "8")
def but9():
    ui.lineEdit.setText(ui.lineEdit.text() + "9")
def but_pl():
    ui.lineEdit.text() t
    ui.lineEdit.setText("")
    time.sleep(0.4)
    ui.lineEdit.setText(t)

    
#   кнопки
ui.but1.clicked.connect( but1 )
ui.but2.clicked.connect( but2 )
ui.but3.clicked.connect( but3 )
ui.but4.clicked.connect( but4 )
ui.but5.clicked.connect( but5 )
ui.but6.clicked.connect( but6 )
ui.but7.clicked.connect( but7 )
ui.but8.clicked.connect( but8 )
ui.but9.clicked.connect( but9 ) 
ui.but_pl.clicked.connect( but_pl )

#   основной код                        

sys.exit(app.exec_())

现在让我们关注函数def but_pl()。
需要将\u200b\u200bof的值lineEdit写入变量,然后lineEdit清零。在这种情况下,我将变量中的值输出回lineEdit.
告诉我如何实现它?

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