# Appending texto to winget from 'regular' function

**URL:** <https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103>\
**Category:** Python Help\
**Created:** [April 22, 2023, 8:17pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103 "2023-04-22T20:17:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HMartins](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@HMartins](https://discuss.python.org/u/HMartins)\
**Post date:** [April 22, 2023, 8:17pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103/1 "2023-04-22T20:17:33Z")

</div>

Hi,

This is a demo Python project using Python (of course), PyCharm and QtDesigner.

The Start button works OK but I can’t find out the proper syntax to be able to append text to the textEdit widget from the main\_proc() function.

Please have a look at the notes within the code below:

```python
import sys

from PyQt5.QtWidgets import *
from PyQt5 import uic

class PlotGUI(QMainWindow):

 def __init__ (self):
     super(PlotGUI, self). __init__ ()
     uic.loadUi("PlotGUI.ui", self)
     self.show()

     self.pushButton_Start.clicked.connect(main_proc)

     self.textEdit_log.append("Hi!") # >>>>>>>>>>>>>>> This one works OK

def main_proc():

 print("Appended Text") # This appends text to the 'regular' text output console (ou sort of).
 # >>>>>>>>>>>>>>> I need to append text to textEdit_log from here <<<<<<<<<<<<<<<<<<<

def main():
 app = QApplication([])
 window = PlotGUI()
 app.exec_()

if __name__ == ' __main__':
 main()

```

Could I have some help please?  
I will try to upload a .rar with the all the related files, I don’t know yes if it is possible. [looks like it is not]  
Thanks  
H. Martins

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [April 22, 2023, 9:06pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103/2 "2023-04-22T21:06:46Z")

</div>

After app.exec\_() is called only code running in event handlers will be called.  
That assumes you have something generating an event, like a button.

Your main\_proc is not connected to anything so will never be used.

Don’t post a rar of code, many people will never open it as its a security risk.  
Just make your code small enough to post here for comment.

---

<div class="post-metadata">

**Author:** ![HMartins](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@HMartins](https://discuss.python.org/u/HMartins)\
**Post date:** [April 22, 2023, 9:57pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103/3 "2023-04-22T21:57:01Z")

</div>

Thank you.

main\_proc runs by:

```auto
self.pushButton_Start.clicked.connect(main_proc)

```

and indeed it runs.

… but can’t I append text to textEdit\_log from there?

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [April 22, 2023, 10:26pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103/4 "2023-04-22T22:26:32Z")

</div>

Why don’t you make `main_proc` a method?

---

<div class="post-metadata">

**Author:** ![HMartins](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@HMartins](https://discuss.python.org/u/HMartins)\
**Post date:** [April 22, 2023, 11:02pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103/5 "2023-04-22T23:02:47Z")

</div>

Well, I have lots of code already written called by main\_proc and I need not only to interact reading widget contents there but also in several other functions.

The code needs to read the content of several widgets (that do not change after the Start button is pressed).

At the moment I do all that changing variable content in declaration but I would like to ‘humanise’ using, say Windows style interfacing.

---

<div class="post-metadata">

**Author:** ![HMartins](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@HMartins](https://discuss.python.org/u/HMartins)\
**Post date:** [April 22, 2023, 11:11pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103/6 "2023-04-22T23:11:08Z")

</div>

This is the real main\_proc:

```python

def main_proc():

    data_out("IN; ") # Inicializar
    data_out("DF; ") # Default
    data_out("SP1; ") # Select pen
    data_out("IN; ") # Inicializar
    data_out("DF; ") # Default
    data_out("PA; ") # Plot absolute
    data_out("VS1; ") # velocidade
    data_out("PU; ") # PenUp

    path_proc()
    polygon_proc()
    circle_proc()

    data_out("SP0; ") # Repõe caneta
    #data_out("DF; ") # Default
    #data_out("IN; ") # Inicializar

    print(s_filename2)

```

> ```
> path_proc()
> polygon_proc()
> circle_proc()
> 
> ```

These three functions call other etc, and they all need to read the content of the widgets and append text do textEdit\_log

I need to replace many "print"s by writing in textEdit\_log.

---

<div class="post-metadata">

**Author:** ![HMartins](https://avatars.discourse-cdn.com/v4/letter/h/71c47a/32.png) [@HMartins](https://discuss.python.org/u/HMartins)\
**Post date:** [April 23, 2023, 6:18pm UTC](https://discuss.python.org/t/appending-texto-to-winget-from-regular-function/26103/7 "2023-04-23T18:18:51Z")

</div>

I found a solution:

```python
class PlotGUI(QMainWindow):

    def __init__ (self):
        super(PlotGUI, self). __init__ ()
        uic.loadUi("PlotGUI.ui", self)
        self.show()

        global txt_log # <<<<<<<<<<<<<< these two lines
        txt_log = self.textEdit_log # <<<<<<<<<<<<<< these two lines

```

Then a small aggregating (append + repaint) function

```python
def txt2log(str):
    txt_log.append(str)
    txt_log.repaint()

```

And finnaly,

```python
txt2log("appending text")

```

placed in any other function is doing the job.

Thank you  
H. Martins
