Find active PyQT5 textline and add result to dictionary - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Find active PyQT5 textline and add result to dictionary (/thread-20200.html) |
Find active PyQT5 textline and add result to dictionary - mart79 - Jul-31-2019 Hi all, I am starting with PyQT5 to set-up a GUI. However, I am new to PyQT5 so therefore the question if there is an instruction to get the name of the active textline or to collect the contents of the textline without addressing the textline directly. Currently I have the following code: def add_liner(self): self.cntLiner += 1 print(self.cntLiner, self.cntPipe) self.pipeproperty[self.cntPipe][self.cntLiner] = {} lining_name = self.inputLining_name.text() self.pipeproperty[self.cntPipe][self.cntLiner]["Name"] = lining_name lining_t = self.inputLining_t.text() self.pipeproperty[self.cntPipe][self.cntLiner]["t"] = lining_t lining_rho = self.inputLining_Rho.text() self.pipeproperty[self.cntPipe][self.cntLiner]["t"] = lining_rhoThe GUI consists of the following textlines: inputLining_name inputLining_t inputLining_rho inputCoating_name inputCoating_t inputCoating_rho Is there a cleaner/clever way of collecting the results of a textline and add it to a dictionary? RE: Find active PyQT5 textline and add result to dictionary - Denni - Jul-31-2019 You could store each text line object in a dictionary and then reference it via some key value but this is only refocusing the reference to the object. In the end there is no way to reference an object without somehow referencing that object no matter how you might obfuscate that reference. Still I guess the overall trick is to view it as an object rather than a textline as this opens the door to doing fairly generic things with all the objects that have similar aspects such as referencing all textlines in a similar manner or via a similar container or any numerous other ways you might handle the object in a more general or generic way. RE: Find active PyQT5 textline and add result to dictionary - mart79 - Jul-31-2019 (Jul-31-2019, 12:45 PM)Denni Wrote: You could store each text line object in a dictionary and then reference it via some key value but this is only refocusing the reference to the object. In the end there is no way to reference an object without somehow referencing that object no matter how you might obfuscate that reference. Still I guess the overall trick is to view it as an object rather than a textline as this opens the door to doing fairly generic things with all the objects that have similar aspects such as referencing all textlines in a similar manner or via a similar container or any numerous other ways you might handle the object in a more general or generic way. Thanks for the information, but I have no idea what I should do. Do you have an example? RE: Find active PyQT5 textline and add result to dictionary - Denni - Jul-31-2019 None-runable example of what I mean -- this works by the way if put into a window of some sort. self.TextLine1 = QLineEdit() self.TextLine2 = QLineEdit() self.TxtLineDict = {} self.TxtLineDict[1] = self.TextLine1 self.TxtLineDict[2] = self.TextLine2 self.TxtLineDict[2].setText('Setting Text in Line Edit 2')Note: I chose numbers to use as keys but you can use anything to use as a key based off of what makes most sense for whatever you are striving to achieve -- this just makes referencing numerous like objects generically a lot easier And again this is just one way to accomplish what you described but it is not the only way I am sure. |