Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 运行程序时的消息框或进度条_Python_User Interface_Popup_Progress Bar_Easygui - Fatal编程技术网

Python 运行程序时的消息框或进度条

Python 运行程序时的消息框或进度条,python,user-interface,popup,progress-bar,easygui,Python,User Interface,Popup,Progress Bar,Easygui,我一直在为自己创建一个程序,我的公司最近想使用它。但是最终用户没有python经验,所以我使用EasyGUI为他们制作了一个GUI。他们所要做的就是单击桌面上的快捷方式(我使用的是pythonw.exe,所以没有显示任何框)。运行该过程大约需要10秒,但执行此操作时会出现一个空白屏幕 我的问题是:我是否可以在函数运行时有一个消息框显示“正在运行…”,然后在整个过程完成时关闭 奖励点:在进程运行时有一个进度条 现在我已经做了一些搜索,但有些东西是我无法理解的(我对Python相当陌生)。我不知道如

我一直在为自己创建一个程序,我的公司最近想使用它。但是最终用户没有python经验,所以我使用EasyGUI为他们制作了一个GUI。他们所要做的就是单击桌面上的快捷方式(我使用的是pythonw.exe,所以没有显示任何框)。运行该过程大约需要10秒,但执行此操作时会出现一个空白屏幕

我的问题是:我是否可以在函数运行时有一个消息框显示“正在运行…”,然后在整个过程完成时关闭

奖励点:在进程运行时有一个进度条

现在我已经做了一些搜索,但有些东西是我无法理解的(我对Python相当陌生)。我不知道如何将这些部分合并到我的代码中。有什么像EasyGUI这样简单的方法可以解决我的问题吗?谢谢

相关职位:


如果您确实需要查看我的代码,我可以尝试在不泄露信息的情况下重新创建它。上级希望我不要泄露这个项目的信息,因为这里的安全性很高

我为你写了一个小演示。不知道这是否正是你想要的。。。 代码在执行其他操作时使用线程更新progressbar

import time
import threading
try:
    import Tkinter as tkinter
    import ttk
except ImportError:
    import tkinter
    from tkinter import ttk


class GUI(object):

    def __init__(self):
        self.root = tkinter.Tk()

        self.progbar = ttk.Progressbar(self.root)
        self.progbar.config(maximum=10, mode='determinate')
        self.progbar.pack()
        self.i = 0
        self.b_start = ttk.Button(self.root, text='Start')
        self.b_start['command'] = self.start_thread
        self.b_start.pack()

    def start_thread(self):
        self.b_start['state'] = 'disable'
        self.work_thread = threading.Thread(target=work)
        self.work_thread.start()
        self.root.after(50, self.check_thread)
        self.root.after(50, self.update)

    def check_thread(self):
        if self.work_thread.is_alive():
            self.root.after(50, self.check_thread)
        else:
            self.root.destroy()        


    def update(self):
        #Updates the progressbar
        self.progbar["value"] = self.i
        if self.work_thread.is_alive():
            self.root.after(50, self.update)#method is called all 50ms

gui = GUI()

def work():
    #Do your work :D
    for i in range(11):
        gui.i = i
        time.sleep(0.1)


gui.root.mainloop()

如果有帮助,请告诉我:)

我已经为您编写了一个小演示。不知道这是否正是你想要的。。。 代码在执行其他操作时使用线程更新progressbar

import time
import threading
try:
    import Tkinter as tkinter
    import ttk
except ImportError:
    import tkinter
    from tkinter import ttk


class GUI(object):

    def __init__(self):
        self.root = tkinter.Tk()

        self.progbar = ttk.Progressbar(self.root)
        self.progbar.config(maximum=10, mode='determinate')
        self.progbar.pack()
        self.i = 0
        self.b_start = ttk.Button(self.root, text='Start')
        self.b_start['command'] = self.start_thread
        self.b_start.pack()

    def start_thread(self):
        self.b_start['state'] = 'disable'
        self.work_thread = threading.Thread(target=work)
        self.work_thread.start()
        self.root.after(50, self.check_thread)
        self.root.after(50, self.update)

    def check_thread(self):
        if self.work_thread.is_alive():
            self.root.after(50, self.check_thread)
        else:
            self.root.destroy()        


    def update(self):
        #Updates the progressbar
        self.progbar["value"] = self.i
        if self.work_thread.is_alive():
            self.root.after(50, self.update)#method is called all 50ms

gui = GUI()

def work():
    #Do your work :D
    for i in range(11):
        gui.i = i
        time.sleep(0.1)


gui.root.mainloop()

如果有帮助,请告诉我:)

我建议您看看python的tkinter包。这里有一个简单的例子:@Peter234,一个进程完成后,如何让消息框停止?请查看我的示例:)我建议您看看python中的tkinter包。这里有一个简单的例子:@Peter234,当一个过程完成后,如何让消息框停止?请看我的例子:)哇!谢谢你。这有点超出我的想象哈哈。不过,我似乎无法在酒吧突然出现的情况下让它运行:(有关于tkinter、ttk甚至progressbar的文档吗?我找不到任何关于模块中有哪些函数的文档,如果我找到了,它们也没有多大帮助。我注意到在Python中,每个模块几乎都有不同的语言哈哈。@Peter234,我真的很感激。@matter:这个脚本是为Python 3编写的,它不会运行。)对于Python 2.7,这可能就是问题所在。有关tkinter的信息,请看这里:@MattR:我对代码做了一些更改。现在它可以在Python 2.7和Python 3上工作:)哇!谢谢。这有点让我不知所措。哈哈。我似乎无法在弹出条的情况下运行它,不过:(有关于tkinter、ttk甚至progressbar的文档吗?我找不到任何关于模块中有哪些函数的文档,如果我找到了,它们也没有多大帮助。我注意到在Python中,每个模块几乎都有不同的语言哈哈。@Peter234,我真的很感激。@matter:这个脚本是为Python 3编写的,它不会运行。)对于Python2.7,这可能就是问题所在。有关tkinter的信息,请看这里:@MattR:我对代码做了一些更改。现在它可以在Python2.7和Python3上工作:)