Python TKinter带百分比的加载条--特定代码

Python TKinter带百分比的加载条--特定代码,python,tkinter,Python,Tkinter,如何使此特定加载条形码同时显示百分比。有人能帮我把它放在一个TKInter窗口中,然后关闭那个特定的TKInter窗口吗 print 'LOADING' toolbar_width = 40 for i in range(toolbar_width): time.sleep(0.1) # do real work here # update the bar sys.stdout.write("-") sys.stdout.flush() sys.stdou

如何使此特定加载条形码同时显示百分比。有人能帮我把它放在一个TKInter窗口中,然后关闭那个特定的TKInter窗口吗

print 'LOADING'

toolbar_width = 40


for i in range(toolbar_width):
    time.sleep(0.1) # do real work here
    # update the bar
    sys.stdout.write("-")
    sys.stdout.flush()

sys.stdout.write("\n")

根据你的代码,我看不到任何地方打印的百分比

您希望如何同时打印它?在哪里

我个人认为有多种选择:

  • 使用Tkinter并在顶部或旁边使用不同的小部件,同时增加这两个值
  • 使用控制台输出,您可以清除控制台并根据您的进程打印格式化字符串(如“----70%”)
如果你想使用
tkinter
你应该首先创建你的脚本,然后试着运行它,如果你遇到错误,你可以针对特定的问题集提出一个带有特定错误的SO问题

正如Bryan之前提到的,这不是某种“LetMeCodeThatForYou”平台。尽管如此,我还是会附加一些伪代码作为可以完成的提示

您可以在一些tkinter代码中尝试以下内容:

import Tkinter as tk
class MyWidget(tk.Window):
    def __init__(self, *args, **kwargs):
        # [...] for real code there needs to be more in here...
        self.percentage=tk.StringVar()
        self.progressbarwidget=SomeWidget(self)
        self.progressbarwidget.grid()        
    def increase_counter(step=1):
        self.percentage.set("%s%%"%(int(self.percentage.get()[-1:])+step))
        self.progessbarwidget.configure(width=width+step)
        if self.percentage.get()=="100%":
            #destroy the window / widget / whatever here...
            self.destroy()
        else:
            self.after(1000, self.increase_counter)
在您的应用程序中使用类似的东西将同时更新小部件的百分比值和外观

请注意,这是唯一的示例代码,这是一种类似于您希望的结构如何实现的提示


还可以看看这里

Stackoverflow不是一种代码编写服务。你有没有遇到问题的具体部分?是的,因为我总是在仪表板加载条之前或之后得到百分比,但从不同时得到