Tkinter 不确定进度条未运行 [英] Tkinter indeterminate progress bar not running

查看:92
本文介绍了Tkinter 不确定进度条未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为 Python 2.7 创建 Tkinter Gui,但在处理进度条时遇到问题.我需要将较大的文件加载到我的程序中,这需要一些时间,所以我想要一个进度条来向用户显示程序没有冻结加载文件.不幸的是,我的进度条在加载文件时似乎没有更新:( 我已经尝试为进度条创建一个新线程但没有运气.所以我想知道我需要做什么才能让不确定的进度条在加载期间运行一个繁重的函数调用?

I'm currently creating a Tkinter Gui for Python 2.7 and having trouble working the progress bar. I need to load largish files into my program which takes some time, so I wanted to get a progress bar to show the user the program isn't frozen loading the files. Unfortunately my progress bar does not seem to update while loading files :( I've tried creating a new thread for the progress bar with no luck. So I'm wondering what do I need to do to get an indeterminate progress bar to run during a heavy function call?

我的代码的相关部分如下:

What the relevant parts of my code looks like are:

import Tkinter as tk
import ttk as ttk
import pandas as pd
import tkFileDialog as tfgiag

self.pb = ttk.Progressbar(frame, orient=tk.VERTICAL, mode='indeterminate')
mynewdata = tfgiag.askopenfilenames(parent=root,title='Choose a file',filetypes=[('CSV files', '.csv')])
self.t = threading.Thread(target = self.pb.start)
self.t.start()  
#read in each CSV file selected by the user
for myfile in root.tk.splitlist(mynewdata): 
    foo = pd.read_csv(myfile)    
    self.data.appendMainData(foo)
self.pb.stop()

推荐答案

在每个 self.pb.step(x) 语句之后使用 self.frame.update_idletasks(),其中'x'代表progressbar的值增加的值

use self.frame.update_idletasks() after every self.pb.step(x) statement,where 'x' stands for the value by which progressbar's value increases

这篇关于Tkinter 不确定进度条未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆