Back to working on a program I started and partially finished back in late Nov/early Dec.
I want to send a value to a program/thread, reset the value and do it again, 11 times. The programs/threads will be running simultaneously right alongside the main program/thread. I want the 'child threads' to report back to the main program/thread and the main thread will display on a gui where each of the threads is currently processing so I can have a rough idea of how much longer it will be before the entire task is finished. This was the original concept now I'm looking at combining another program with this, which will be downloading other images from the internet, while this one is searching the internet for certain audio/video files. This part of the program will take longer to execute then the image downloads(45 minutes, roughly versus 4-5 minutes for the image downloads).
Once the image downloads are finished I want to be able to look through the images. Hence the mother thread would have to be 'fully functional' not tied up.
This idea keeps expanding as I keep learning more of the capabilities I have with Python that I never really had with VB6.
I saw in old post a few minutes ago that Tkinter only works with the main thread. Hence the reason I was always getting the errors in the code below.
Is there a way, without locking up the main program/thread that I can have the child threads report back to the main thread and have the main thread update the screen while still letting the main thread function normally(download/display images)?
Here's a look at where I'm currently starting from.
import os
import sys
import urllib
from tkinter import *
import threading
import time
class Startup:
def __init__(self, root):
self.DrawArea = Canvas(root, height=250, width=200,bg = 'black')
self.starthere()
def dl_0(self):
self.NxtNum0 = int(self.HiStr0)
while self.NxtNum0 < int(self.HiStr0)+100:
self.DrawArea.create_text(50,12,text = str(self.NxtNum0), fill = 'white', tags = '0')
self.NxtNum0 +=1
#download routine goes here once the on screen update routine gets straightened out, time.sleep(.1) will be removed
time.sleep(.1)
#self.DrawArea.delete('0')
def dl_1(self):
self.NxtNum1 = int(self.HiStr1)
while self.NxtNum1 < int(self.HiStr1)+100:
self.DrawArea.create_text(50,37,text = str(int(self.NxtNum1)), fill = 'white', tags = '1')
self.NxtNum1 +=1
#download routine goes here once the on screen update routine gets straightened out, time.sleep(.1) will be removed
time.sleep(.1)
#self.DrawArea.delete('1')
#continue on through all 11 threads
def starthere(self):
#find current highest value
Hival = open("Highest.txt", "r")
Histr = Hival.read()
Hival.close()
self.HiStr0 = str(int(Histr)+1)
HiStra = int(int(Histr)/10000)
#call download #0
dl0 = threading.Thread(target = self.dl_0, name = 'dl0')
dl0.start()
#setup/call download #1
self.HiStr1 = str(str(HiStra+1)+"0000")
dl1 = threading.Thread(target = self.dl_1, name = 'dl1')
dl1.start()
#continue on down through all 11 threads
if (__name__ == "__main__"):
os.chdir ('/media/')
root = Tk()
root.geometry("200x250")
Thr = Startup(root)
The above, like I said above is from trying most of the day without internet access to get this thing to work right. It's definitely written a bit screwy compared to what it should be now that I think I understand the Tkinter limitation.
I fess in the original partially finished version I was creating 11 separate guis/programs using subprocess. They had no way of sending back the values to the main program(at least not that I know of). I like the idea much better of using just one program and having the child threads report back and the main thread and having the main thread continually update the screen showing the file number of the file that is currently being looked at in each of the 11 child threads. Can I do this and still have the screen updated and be able to continue to use and display other threads(non 11 above) at the same time or not?
I hope this isn't totally confusing...sorry if it is.