I can not add many values in one function

2024/10/11 20:29:55

I have a gui application

  1. I put text into text box1, text box2,………… text box70 ,and then click on the pushButton,

  2. The function return_text () in the module_b.py be called. Now I can call one instance by lambda1 function and use it in class_b, but I can not call 70 instances when I click on the pushbutton.

**A- I want add lineEdit_1 , lineEdit_2 ….. lineEdit_70 into lambda method in main.py

**B- I want to edit (return_text (self, txt)) and (table2 (self, txt) ) in the module_b.py to print and return values from . student1 to student70

Can anyone help me? Here's the code for that :

main.py

# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import sys
from GUI import Ui_MainWindow
class MainWindow(QtGui.QMainWindow,Ui_MainWindow):def __init__(self, parent=None):QtGui.QWidget.__init__(self, parent)self.ui = Ui_MainWindow()self.ui.setupUi(self)from module_b import calss_bglobal instance_binstance_b=calss_b(self)txt1 = self.ui.lineEdit.text #Method reference not Method calltxt2 = self.ui.lineEdit2.text mySlot = lambda : (instance_b.return_text_username(txt1()) QtCore.QObject.connect(self.ui.pushButton,QtCore.SIGNAL("clicked()"),mySlot)if __name__ == "__main__":app = QtGui.QApplication(sys.argv)global myappmyapp = MainWindow()myapp.show()sys.exit(app.exec_())

module_b.py

import sys
from GUI import Ui_MainWindow
from PyQt4 import QtCore, QtGui
class calss_b (object):def __init__(self, parent=None):passdef return_text (self, txt):####  global student1, student2 , student3………. Student70student1=unicode(txt) return first_student
#####   ….…return 70def table2 (self, txt):print student1print 2
#####   ….…print 70
Answer

The best way I can thing of, is to collect all the lineEdit into a list and pass it to return_text method then call text() method in each iteration, this way:

number_of_line_Edit = 70
txt = [getattr(self.ui,'lineEdit{0}'.format(i)) for i in range(1,number_of_line_Edit+1)] #This will collect all lineEdit(s) reference so we can call there methods in return_text method
mySlot = lambda :instance_b.return_text(txt)
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"),  mySlot) 

Then in return_text and table2 methods of module_b.py :

def return_text(self, lineEdit_list):my_text_list = []for t in lineEdit_list:txt = unicode(t.text())self.table2(txt)my_text_list.append(txt)#print my_text_list for checking purposereturn my_text_list## I want print password and return it.   
def table2(self, my_txt):print my_txt

Note that my_text_list list will be always reset to empty list every time return_text method is called, where it will lose all texts of lineEdit(s) of previous call.

https://en.xdnf.cn/q/118282.html

Related Q&A

Close browser popup in Selenium Python

I am scraping a page using Selenium, Python. On opening the page one Popup appears. I want to close this popup anyway. I tried as below:url = https://shopping.rochebros.com/shop/categories/37browser = …

How can I replace certain string in a string in Python?

I am trying to write two procedures to replace matched strings in a string in python. And I have to write two procedures. def matched_case(old new): .........note: inputs are two strings, it returns a…

Python: `paste multiple (unknown) csvs together

What I am essentially looking for is the `paste command in bash, but in Python2. Suppose I have a csv file:a1,b1,c1,d1 a2,b2,c2,d2 a3,b3,c3,d3And another such:e1,f1 e2,f2 e3,f3I want to pull them toget…

Django Redirect after Login Error

Im new to Django and I know that to redirect after login I have to set the parameter page. But this only works when the login is successful. How can i do the same thing when some error occurs?? Ps: I…

Python: Pulling .png from a website, outputting to another

Hoping this question is not too vague, or asking for too much. Essentially I am analyzing large amounts of spectra, and wanting to create one large webpage that contains these spectra rather than looki…

Using peakutils - Detecting dull peaks

Im currently using peakutils to find peaks in some data. My data contains some "dull peaks", that is my peaks plateau somewhat. I cant set my code to find these peaks even after playing aroun…

nonlinear scaling image in figure axis matplotlib

enter image description hereI hope I have not over-looked as previously asked question. I dont think so. I have an image of a spectrum. I have several laser lines for calibration. Since the laser li…

How to correctly call a git submodule symlinked?

On the Sublime Text Package Control issue:Why ignore VCS-based packages accordingly to this message? I find out what causes this error. I had the package All Autocomplete triggering it. Then I gone to…

Python and MySQL query with quotes

With a script in Python3, after extracting some strings from a file, they should be used as data to be inserted into a MySQL database as follows:query1 = """INSERT INTO {:s} VALUES ({:s}…

Using scipy kmeans for cluster analysis

I want to understand scipy.cluster.vq.kmeans. Having a number of points distributed in 2D space, the problem is to group them into clusters. This problem came to my attention reading this question and …