1

Im trying to make a progress bar that in tkinter using asycio. I have written this code as test, but it doesn't seem to show the progress as function goes along. Im hoping that the user will be able to see the progress bar go forward until the plot comes up. Any advice, fixes, or alternative solutions would be appreciated. Thanks!

import asyncio
import time
import matplotlib.pyplot as plt
import threading
from tkinter import *
from tkinter import ttk

root = Tk()

root.geometry("250x250")

lox = [1,2,3,4,5]
loy = lox

pb = ttk.Progressbar(root, orient='horizontal', mode='determinate')
pb.pack(pady=20)

async def pb_forward():
    pb['value'] += 50

async def say_after(delay, what):
    time.sleep(delay)
    print(what)

def get_xy(lox, loy):
    time.sleep(5)
    return [lox,loy]
    

async def main():
    await pb_forward() 
    x = get_xy(lox,loy)[0]
    await pb_forward()
    y = get_xy(lox,loy)[1]
    plt.plot(x,y)
    plt.show(block = False)

def run_it():
    asyncio.run(main())


my_button1 = Button(root, text="Start", command=run_it)
my_button1.pack(pady=20)

root.mainloop

0 Answers0