[Python] Python, Return from subroutine, using tkinter progress bar

Discussão em 'Python' iniciado por Stack, Julho 25, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing a script that uses tkinter progress bar that tracks the number of files done.

    I have a list of files that I want to process, each file would be processed in the subroutine.

    In the subroutine I need to check each line in the file.

    My subroutine (my_sub_routine(k)) never returns.

    from tkinter import *
    from tkinter.ttk import *

    def my_sub_routine(k):
    p = 0
    def test_read(p):
    print("reading line number",p,",number of lines to read = ",k)
    if p < k:
    p += 1
    test_read(p)

    if p == k:
    print("should be gone")
    return None
    test_read(p)

    def main():
    GB = 15 # this would be number of file to process
    root = Tk()
    root.title("Progress Window")
    root.geometry("300x300")
    progress = Progressbar(root, orient=HORIZONTAL, length=200 , maximum=GB)
    progress.pack()
    i = 0
    def my_func(i):
    i += 1
    progress['value'] = i
    print("i: ",i)
    root.after(1000, my_sub_routine,10) #this would be a filename with 10 lines in it.
    if i == GB:
    quit()
    my_func(i)
    mainloop()

    if __name__ == '__main__':
    main()

    Continue reading...

Compartilhe esta Página