1

I have the following python36 code which is checking values, and then set a tkinter label that the entry values has been accepted, to then execute another threaded function. Before and after the function as well as inside the function I would like to display something in a tkinter scrolledtext box. Like it where a console/shell.

  1. All the label.configure() as well as scrolledtext.insert() are only getting displayed all at the same time after everything has been run.

  2. I am not able to use the scrolledtext.insert() inside the threaded function (fundamentals question, could I use it inside a function of an imported module?)

I would like to have the execution time of these functions like if I would use the print() function. So execute it as soon as the script went over it. It would be nice if you could explain to me why this is not executed immediately since I am currently learning python or point me to the appropriate reference.

        elif str(x2) == 'None' and str(x3) == 'None':
            E2T = 'accepted'
            E2L.configure(text=E2T, fg="green")
            E2L.grid(row=5, column=2)
            E3T = 'accepted'
            E3L.configure(text=E3T, fg="green")
            E3L.grid(row=6, column=2)
            # Start scanning process
            scrolledtext.insert(tkinter.INSERT, 'Start scanning....\n' )
            print('testprint')
            portlist = scan(E1.get(),E2.get(),E3.get())
            # try work with returned value and display as in a console
            print(portlist)
            print('testprint')
            scrolledtext.insert(tkinter.INSERT, 'Following Ports are open\n' )
            scrolledtext.insert(tkinter.INSERT, str(portlist))
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
veritaS
  • 511
  • 1
  • 5
  • 23
  • 1
    1) Does `scan` block until it has its information? If so, that is probably why data is not being displayed until `scan` completes. 2) As long as you provide the scrolledtext object to an imported module by passing it as a function or method parameter, you can write to the scrolledtext widget from that imported module. – Ron Norris Jul 20 '17 at 00:40
  • 1) it appears I have problems with global/local variables. I am trying to get around this by revisiting the documentations 2) thats a good idea, i´ll try that. – veritaS Jul 20 '17 at 02:22

1 Answers1

0

You can do scrolledtext.update_idletasks() after a scrolledtext.insert(), it will refresh the widget and your text will pop. see that comment for more. Hope it help!

Gnawavibes
  • 91
  • 8