Python 将progressbar连接到单个功能+tkinter gui
我已经查看了其他用户提出的各种其他问题,但没有找到我要查找的内容,如果我遗漏了什么,请告诉我。我正在寻找一种简单的方法,将progressbar连接到tkinter GUI中的每个函数。我是python新手,因此仍在学习如何做基本的事情。我希望progressbar在用户按下按钮时以确定模式更新,这样他们就知道GUI仍在工作,并且知道完成每个任务还剩下多少时间。例如,当他们单击script1时,我如何为progressbar编写代码,在完成该任务期间进行更新?下面是我的代码:Python 将progressbar连接到单个功能+tkinter gui,python,user-interface,tkinter,Python,User Interface,Tkinter,我已经查看了其他用户提出的各种其他问题,但没有找到我要查找的内容,如果我遗漏了什么,请告诉我。我正在寻找一种简单的方法,将progressbar连接到tkinter GUI中的每个函数。我是python新手,因此仍在学习如何做基本的事情。我希望progressbar在用户按下按钮时以确定模式更新,这样他们就知道GUI仍在工作,并且知道完成每个任务还剩下多少时间。例如,当他们单击script1时,我如何为progressbar编写代码,在完成该任务期间进行更新?下面是我的代码: from sys
from sys import exit
from Tkinter import *
from subprocess import Popen, PIPE
import os
import time
import sys
import ttk
Root = Tk()
Root.title("PIER PROCESSING GUI")
class Command:
def __init__(self, func, *args, **kw):
self.func = func
self.args = args
self.kw = kw
def __call__(self, *args, **kw):
args = self.args+args
kw.update(self.kw)
self.func(*args, **kw)
def script1(Where):
Cmd = "build_new_pier %s"%Where
print "Cmd =", Cmd
Sp = Popen(Cmd, shell = True, stderr = PIPE)
Ret = Sp.stderr.read()
if len(Ret) != 0:
print Ret
return
def quitter():
exit(0)
Label(Root, text = "Push button to build a new PIER").pack(side = TOP, pady = 5)
Sub = Frame(Root)
Button(Sub, text = "build_new_pier WEST", command = Command(script1, \
"WEST")).pack(side = LEFT, pady = 5)
Button(Sub, text = "build_new_pier EAST", command = Command(script1, \
"EAST")).pack(side = LEFT, pady = 5)
Button(Sub, text = "build_new_pier SOUTH", command = Command(script1, \
"SOUTH")).pack(side = LEFT, pady = 5)
Sub.pack(side = TOP)
Button(Root, text = "Quit", command = quitter).pack(side = TOP, pady = 5)
Root.geometry("700x500+500+500")
Root.mainloop()
我只包括了第一个脚本调用,因为其他调用实际上是相同的。在函数外部调用progressbar(即测量每个函数的progressbar)是否更好?或者我应该将progressbar连接到每个单独的函数吗?不管怎样,我如何构建这样一个东西?提前感谢。你可以看看这些帖子:我提供了一个进度条在特定时间内连续移动的例子 适合您的用例可能是:
Create a thread
Call your shell command through "popen" in this thread
While waiting the thread end, make the progress bar moving !
Return the result and delete the progress bar.
我让你试试这个,并更新你的问题,以提供更新的尝试。
因为我不知道我应该给波本打电话给哪张纸条,所以我不能做更多的事来帮助你,对不起。是否真的需要调用外部票据
祝你好运
亚瑟