Python Forum
[Tkinter] Defining a self made module's function to interact with the main .py variables?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Defining a self made module's function to interact with the main .py variables?
#10
Man I must thank you!
you made me break my head with that listener thread and now I got it working!! (still shocked about it lol)
I gave up on trying to read the std and just merged the files into one and did some re-design.
now I got 3 threads running with 1 communicating with the widget.

here it is:

    def thread_handler(self, host):

        wt = threading.Thread(target=self.write_to_file, args=(host,))
        pt = threading.Thread(target=self.print_to_box, args=(host,))
        dt = threading.Thread(target=self.delete_default_lines, args=())

        wt.start()
        pt.start()
        dt.start()
also, I started the entire GUI with a thread and kept it alive:

if __name__ == "__main__":

    lock = threading.Lock()
    lock.acquire()
    t = threading.Thread(name="Main GUI", target=main, args=())
    t.start()
and this is the widget update:

    def print_to_box(self, host):
        print(f'Current Proccess: {mp.current_process().name} + {mp.current_process().pid}\n')
        with sub.Popen(["ping", "-n", '4', f'{host}'], stdout=sub.PIPE,
                       bufsize=1, universal_newlines=True, stderr=sub.STDOUT) as p:
            for line in p.stdout:
                self.text_window.insert(tk.END, line)
that did the entire trick.
Thanks again!
Reply


Messages In This Thread
RE: How can I define a selfmade module's functio to interact with the main .py variables? - by Gilush - Jun-08-2020, 09:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I run an interface I made using PyQt5 and a Map program I made using Tkinter bki 6 1,182 Nov-09-2023, 11:12 PM
Last Post: bki
  [PyQt] Managing variables accross a multiple module GUI Oolongtea 18 10,859 Sep-19-2019, 12:13 PM
Last Post: Oolongtea
  “main thread is not in main loop” in Tkinter Long_r 1 24,332 Jun-26-2019, 11:00 PM
Last Post: metulburr
  [Tkinter] Bringing function out of class into main loop zukochew 1 2,689 Jul-30-2018, 06:43 PM
Last Post: Axel_Erfurt
  GTK main window calling a main window DennisT 4 6,833 Oct-19-2016, 09:36 PM
Last Post: DennisT

Forum Jump:

User Panel Messages

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