0

I have trouble entering the output of a function in another scrolledtext class, which I have simplified so that I can better explain.
I have a function in a class (named A) and I want to write it's print content in ScrolledText in another class (B) like below:

import time
class A:
    def func(self):
        for i in range(0, 4):
            print(i)
            time.sleep(0.5)
        pass

I use this method but I do not get an answer:

from tkinter import *
from tkinter.scrolledtext import ScrolledText
In[1]:class B:
          root = Tk()
          def finish():
              text.insert(INSERT, A().func()) # Here I have tried to write in the ScrolledText
                                              # But it does not work
          text = ScrolledText(root)
          text.grid(row = 0, column = 0)

          button_openfile = Button(root, text = 'Start', command = finish)
          button_openfile.grid(row = 1, column = 0)

          root.mainloop()

In[2]:if __name__ == "__main__": 
          B()

1 Answer 1

1

You are not getting the text in the ScrolledText widget because:

text.insert(INSERT, A().func())

In this line, the second parameter(A().func()) is supposed to be a String.

print(i)

When the function is called, Instead of returning the String or text, you just printed it in the terminal. Instead you should return a text.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.