状态对象没有属性“正在加载”

时间:2019-07-02 15:47:08

标签: python tkinter progress-bar

我正在使用面向对象设计在Tkinter中的进度条上,但遇到了问题。

 //turn off run limit timer- this might take a bit
pragma runLim , 0 

Object o 
Module m = current Module

// Recursive function- assumes each object has a text attribute- will error otherwise
void link_print(Object obj) {
    print obj."text" "\n"
    Link out_link
    Object next_obj = null
    Object child_obj = null
    for out_link in obj -> "*" do {
        // Set the next object in the chain
        next_obj = target ( out_link )
        // This might return null if the module is not loaded
        if ( null next_obj ) {
            // Load the module in read-only mode, displayed and in standard view
            read ( fullName ( ModName_ target ( out_link ) ) , true , true )
            // Try and resolve out 'target' again
            next_obj = target ( out_link )
            // If it doesn't work, print a message so we can figure it out
            if ( null next_obj ) {
                print "Error Accessing Object " ( targetAbsNo ( out_link ) )""
            } else {
                // Loop and report on child objects
                for child_obj in next_obj do {
                    print child_obj."text" "\n"
                }
            }
        } else {
            // Loop and report on child objects
            for child_obj in next_obj do {
                print child_obj."text" "\n"
            }
        }
    }
}


for o in entire(m) do {
    // Note that I cast the result of o."IDNUM" to a string type by appending ""
    if (o."IDNUM" "" != ""){
        print o."IDNUM" "\n" 
        // Recurse
        link_print(o)
        print "\n"
    }
}

我应该获得一个无限加载的进度条,但我却得到了

from tkinter import *
from tkinter import ttk

class Status:
    def __init__(self):
        self.root = Tk()
        self.root.geometry("400x20")
        self.loading = ttk.Progressbar(self.root, length=15, value=0, orient=HORIZONTAL, command=self.start_progress())
        self.loading.pack(fill=X)
        self.root.mainloop()

    def start_progress(self):
        self.loading.start(10)

bar = Status()

我想要的是进度条自动更新,而无需使用任何按钮。它应该装满并在充满时停止。

1 个答案:

答案 0 :(得分:0)

通常,您将创建一个IntVar并将其设置为Progressbar的变量。然后,您可以跟踪IntVar上的更改,并在必要时停止。

from tkinter import *
from tkinter import ttk

class Status:
    def __init__(self):
        self.root = Tk()
        self.root.geometry("400x20")
        self.var = IntVar()
        self.loading = ttk.Progressbar(self.root, length=15, variable=self.var, orient=HORIZONTAL)
        self.loading.pack(fill=X)
        self.var.trace("w",self.trace_method)
        self.start_progress()
        self.root.mainloop()

    def start_progress(self):
        self.loading.start(10)

    def trace_method(self,*args):
        if self.var.get() >= 99: #when it reaches 100 it would go back to 0
            self.loading.stop()

bar = Status()