python脚本执行时弹出/消息

时间:2019-11-28 11:34:55

标签: python user-interface tkinter messagebox tkmessagebox

我想在执行python脚本时显示一条消息(弹出窗口),并在脚本执行完后自动消失

import sys
from tkinter import ttk
from tkinter import messagebox

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

import new_support

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = tk.Tk()
    top = Toplevel1 (root)
    new_support.init(root, top)
    root.mainloop()

w = None
def create_Toplevel1(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = tk.Toplevel (root)
    top = Toplevel1 (w)
    new_support.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_Toplevel1():
    global w
    w.destroy()
    w = None

class Toplevel1:


    def smsdata(self):
        MsgBox = tk.messagebox.showinfo('Analysing', 'Please wait till the data is being analysed')
        * My Script*


    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9' # X11 color: 'gray85'
        _ana1color = '#d9d9d9' # X11 color: 'gray85'
        _ana2color = '#ececec' # Closest X11 color: 'gray92'
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.',background=_bgcolor)
        self.style.configure('.',foreground=_fgcolor)
        self.style.map('.',background=
            [('selected', _compcolor), ('active',_ana2color)])

        top.geometry("534x226+710+62")
        top.minsize(1, 1)
        top.maxsize(1905, 898)
        top.resizable(1, 1)
        top.title("SMS_Analysis")
        top.configure(highlightbackground="#00d81d")

        self.Frame1 = tk.Frame(top)
        self.Frame1.place(relx=0.0, rely=0.0, relheight=0.996, relwidth=1.002)
        self.Frame1.configure(relief='ridge')
        self.Frame1.configure(borderwidth="2")
        self.Frame1.configure(relief="ridge")
        self.Frame1.configure(background="#180bd8")

        self.Execute = tk.Button(self.Frame1)
        self.Execute.place(relx=0.093, rely=0.089, height=104, width=436)
        self.Execute.configure(activebackground="#10ed00")
        self.Execute.configure(activeforeground="#ffffff")
        self.Execute.configure(background="#10d802")
        self.Execute.configure(relief="groove")
        self.Execute.configure(text='''Execute''')
        self.Execute.configure(command=self.smsdata);

        self.Message1 = tk.Message(self.Frame1)
        self.Message1.place(relx=0.224, rely=0.756, relheight=0.133
                , relwidth=0.563)
        self.Message1.configure(text='''Wait For 2 Min''')
        self.Message1.configure(width=301)

        self.TProgressbar1 = ttk.Progressbar(self.Frame1)
        self.TProgressbar1.place(relx=0.093, rely=0.578, relwidth=0.804
                , relheight=0.0, height=19)
        self.TProgressbar1.configure(length="430")

if __name__ == '__main__':
    vp_start_gui()

我想在运行以下代码时显示弹出窗口

def smsdata(self):
        MsgBox = tk.messagebox.showinfo('Analysing', 'Please wait till the data is being analysed')
        * My Script*

执行弹出窗口后应该会消失。

我已经创建了一个 MsgBox ,但是问题是当我按“确定”时脚本开始执行。我希望弹出窗口在执行代码时出现,而在完成执行时消失

new_support

import sys

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

def init(top, gui, *args, **kwargs):
    global w, top_level, root
    w = gui
    top_level = top
    root = top

def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None

if __name__ == '__main__':
    import new
    new.vp_start_gui()

1 个答案:

答案 0 :(得分:0)

如果要查找的答案是要同时处理多个命令,则可以使用多线程模块或线程模块。