作者:台湾菜文 | 来源:互联网 | 2023-07-16 19:09
我有这个文本是使用lineEdit.text()从另一个窗口获得的,事实是,将文本传递到该窗口之后,它不是对象,我需要将文本变成对象才能运行此打印功能通过sqlite删除该文本的数据。我希望有人可以立即帮助我解决这个问题。
这里是我获取文本的窗口中的代码
from PyQt5 import QtCore,QtGui,QtWidgets
from WordWindow import Ui_WordWindow
class Ui_MainWindow(object):
def setupUi(self,MainWindow):
MainWindow.resize(812,617)
self.horizOntalLayout= QtWidgets.QHBoxLayout()
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.lineEdit1 = QtWidgets.QLineEdit(self.centralwidget)
self.horizontalLayout.addWidget(self.lineEdit1)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.clicked.connect(self.openwindow)
self.horizontalLayout.addWidget(self.pushButton)
def openwindow(self):
self.window = QtWidgets.QMainWindow()
self.receiver = self.lineEdit1.text()
self.ui = Ui_WordWindow(self.receiver)
self.ui.setupUi(self.window)
self.window.show()
这是我要将传递给我的文本传递给窗口的代码
import sqlite3
from PyQt5 import QtCore,QtWidgets
cOnn= sqlite3.connect('database.db')
cursor = conn.cursor()
class Ui_WordWindow(object):
def __init__(self,receiver): #Obtaining text from MainWindow
self.receiver = receiver
print (self.receiver) #Testing if it worked or not
def read_From_db(self): # Get the data of text obtained
cursor.execute(('SELECT * FROM mytable WHERE Mean = ?',self.receiver))
data = cursor.fetchall()
print(data)
window2 = Ui_WordWindow(receiver) #This doesnt work because receiver isnt an object/ receiver is not defined
window2.read_From_db()
cursor.close()
conn.close
编辑:我尝试使用getattr,但是没有用,虽然我可能是错了,但我对此表示怀疑