Python 3.6 PyQt5 questions

Asked 1 years ago, Updated 1 years ago, 119 views

Questions about list.py and ui and view.py. I worked with PyQt5 and used pimysql. Please reply. <

==list.py==

coding: utf-8

import sys

import os

from PyQt5 import QtWidgets

from PyQt5 import QtGui

from PyQt5 import uic

from PyQt5 import QtCore

from PyQt5.QtCore import pyqtSlot

import pymysql

conn = pymysql.connect(host='localhost', user='test', password='', db='test', charset='utf8')

curs = conn.cursor()

sql = "select * from customer" curs.execute(sql)

rows = curs.fetchall()

conn.close()

class Form(QtWidgets.QDialog):

def __init__(self, parent=None):

    QtWidgets.QDialog.__init__(self, parent)
    self.ui = uic.loadUi("list.ui", self)
    self.ui.show()

    self.ui.label_2.setText(rows[0][1]) # Kim Jungsoo
    self.ui.label_3.setText(rows[1][1]) # KangSujeong
    self.ui.label_4.setText(rows[2][1]) # Lee Sungjin
    self.ui.label_5.setText(rows[3][1]) #Hongdae

@pyqtSlot()
def write(self):
    os.system('write.py');

if name == 'main':

app = QtWidgets.QApplication(sys.argv)

w = Form()

sys.exit(app.exec())

Here, self.ui.You want to print 10 label_2.setText(rows[0][1]) parts as for statements. But I don't know how. So now I just print them out one by one. How can I turn it to "for door" instead of taking 10 pictures?

If the desired function is page=1, output to 0, 10, and if page=2, 10, 20... I want to print it out like this.

And the other thing I want to do is self.ui.When I click label_2.setText(rows[0][1]), I want to turn over the variable by calling view.py. In short, if you want a function that links you to a view page and you're looking for it because it's Python, how do you apply it?

So here's the question about list.py (and because I made it a Qt Designer, I took the way to bring list.ui to ui, and if I had to py the ui, there was also a blockage there. It's a part of the definition of the write function, and the error is printed first, so it keeps wandering from there. Help me...

AttributeError: 'QDialog' object has no attribute in cmd.

list.ui is the same as the code below when pyized.

-- coding: utf-8 --

Form implementation generated from reading ui file 'C:\Users\Fortis-Aaron\AppData\Local\Programs\Python\Python36-32\Scripts\list.ui'

Created by: PyQt5 UI code generator 5.9.2

WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):

def setupUi(self, Dialog):
    Dialog.setObjectName("Dialog")
    Dialog.resize(400, 300)
    self.label = QtWidgets.QLabel(Dialog)
    self.label.setGeometry(QtCore.QRect(60, 30, 281, 31))
    self.label.setAlignment(QtCore.Qt.AlignCenter)
    self.label.setObjectName("label")
    self.label_2 = QtWidgets.QLabel(Dialog)
    self.label_2.setGeometry(QtCore.QRect(40, 60, 321, 21))
    self.label_2.setAlignment(QtCore.Qt.AlignCenter)
    self.label_2.setObjectName("label_2")
    self.label_3 = QtWidgets.QLabel(Dialog)
    self.label_3.setGeometry(QtCore.QRect(40, 80, 321, 21))
    self.label_3.setAlignment(QtCore.Qt.AlignCenter)
    self.label_3.setObjectName("label_3")
    self.label_4 = QtWidgets.QLabel(Dialog)
    self.label_4.setGeometry(QtCore.QRect(40, 100, 321, 21))
    self.label_4.setAlignment(QtCore.Qt.AlignCenter)
    self.label_4.setObjectName("label_4")
    self.label_5 = QtWidgets.QLabel(Dialog)
    self.label_5.setGeometry(QtCore.QRect(40, 120, 321, 21))
    self.label_5.setAlignment(QtCore.Qt.AlignCenter)
    self.label_5.setObjectName("label_5")
    self.pushButton = QtWidgets.QPushButton(Dialog)
    self.pushButton.setGeometry(QtCore.QRect(310, 260, 75, 23))
    self.pushButton.setObjectName("pushButton")

    self.retranslateUi(Dialog)
    self.pushButton.clicked.connect(Dialog.write) # Commenting on this part works fine, but you cannot run the write function.
    QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
    _translate = QtCore.QCoreApplication.translate
    Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
    self.label.setText(_translate("Dialog", "Title"))
    self.label_2.setText(_translate("Dialog", "Title~"))
    self.label_3.setText(_translate("Dialog", "Title~"))
    self.label_4.setText(_translate("Dialog", "Title~"))
    self.label_5.setText(_translate("Dialog", "Title~"))
    self.pushButton.setText (_translate ("Dialog", "Writing")

if name == "main":

import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())

By pyifying the ui, the error part of the write function is resolved, and the for statement is turned to self.It would be great if you could print 10 label_2.setText(_translate("Dialog", "Title~") according to the page...<

Finally, if you press the 'Write' button on list.py, the write function is executed and write.py is called. At this point, I want to close the open list.py. However, I couldn't find the function to close the parent window even though I tried sys.exit(). In this case, how can we solve it? Please...ㅠ<

The final thing I want is to complete the bulletin board window program through Python and PyQt5. It wasn't that hard to make a bulletin board through the web, but I'm asking a lot of questions to make it into a Windows program through Python and GUI programs. Please give me a question.ㅠ<

list.py (List page), write.py (Writing page), view.py (View page)

python pyqt5 gui window-programming

2022-09-22 19:18

1 Answers

It's not a question, it's a level of asking.

I think it needs to be almost like a lecture to answer.

Windows development is also different from web development. First, study with Qt book.

There are only foreign books for pyqt books, but there are several domestic and translated books for Qt books.


2022-09-22 19:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.