I've been trying to combine the two, but the ThreadPool will not connect to the GUI. Is it even possible to connect the two together?
I am just using this as an example to learn how to use ThreadPooling. I'd like each name to be printed on it's own thread. Eventually I'll be using a Treeview to collect data from their own separate threads, but not sure if it's possible to use with the ThreadPoolExecutor.
Here's what I've tried to no avail:
I am just using this as an example to learn how to use ThreadPooling. I'd like each name to be printed on it's own thread. Eventually I'll be using a Treeview to collect data from their own separate threads, but not sure if it's possible to use with the ThreadPoolExecutor.
Here's what I've tried to no avail:
from tkinter import Tk, Button, Listbox
from concurrent.futures import ThreadPoolExecutor
class MainWindow(Tk):
def __init__(self):
super().__init__()
self.lb1 = Listbox(self, width=26, cursor='hand2')
self.lb1.pack(side='left', fill='y', padx=20, pady=20)
self.b1 = Button(self, text='START', bg='green', fg='white', cursor='hand2', command=self.start)
self.b1.pack(side='left')
self.lb1.insert('end', 'Aaron')
self.lb1.insert('end', 'Billy')
self.lb1.insert('end', 'Chris')
self.lb1.insert('end', 'David')
self.lb1.insert('end', 'Edward')
self.lb1.insert('end', 'Frank')
self.lb1.insert('end', 'George')
self.lb1.insert('end', 'Howard')
self.lb1.insert('end', 'Ian')
self.lb1.insert('end', 'Johnny')
def worker1(self):
for i in range(self.lb1.size()):
print(self.lb1.get(i))
def start(self):
with ThreadPoolExecutor(max_workers=2) as executor:
executor.submit(self.worker1)
if __name__ == '__main__':
app = MainWindow()
app.title('Main Window')
app.configure(bg='#333333')
#center the Main Window:
w = 500 # Width
h = 420 # Height
screen_width = app.winfo_screenwidth() # Width of the screen
screen_height = app.winfo_screenheight() # Height of the screen
# Calculate Starting X and Y coordinates for Window
x = (screen_width / 2) - (w / 2)
y = (screen_height / 2) - (h / 2)
app.geometry('%dx%d+%d+%d' % (w, h, x, y))
#app.maxsize(1400, 620)
app.mainloop()
