Python Forum
Find active PyQT5 textline and add result to dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find active PyQT5 textline and add result to dictionary
#1
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_rho
The 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?
Reply
#2
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.
Reply
#3
(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?
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,913 Apr-16-2022, 04:04 PM
Last Post: DBox
  [Tkinter] how can disable menu [About] when Toplevel is active balenaucigasa 0 2,661 Oct-25-2019, 09:49 PM
Last Post: balenaucigasa
  Active tkinter text output during loop dvanommen 2 10,760 Oct-18-2019, 02:23 PM
Last Post: dvanommen
  [PyQt] Collect entry from textline Widget via UI file mart79 3 2,899 Aug-05-2019, 01:40 PM
Last Post: Denni
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,819 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  PyQt5: Add Variable Number of Rows to Layout Based on Python Dictionary kennybassett 2 4,749 Oct-02-2018, 02:05 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020