【发布时间】:2018-09-03 03:07:17
【问题描述】:
我正在使用一个工具,其中我通过Tkinter GUI 界面获取初始用户凭据和唯一标识符。在经过大量数据获取和处理后,我将使用xlsxwriter 包将报告写入 Excel 工作表。
我通常在单击按钮时使用destroy() 方法退出/关闭 tkinter 窗口。在这里,我想在 Tkinter messagebox 中向用户显示报告创建的状态,然后关闭主窗口。
注意:我使用的是.pyw 扩展,因此使用该工具的最终用户不应该看到控制台。所以一旦用户点击提交按钮,我会在窗口的页脚显示一个标签,上面写着"Processing ..."
示例代码:
from tkinter import *
#Some other libraries are imported
mScrn = Tk()
mScrn.title("Report Generation Tool v1.0")
mScrn.geometry("200x180")
mScrn.resizable(False, False)
tk_uid_lbl = Label(mScrn, text="MVS1 Username")
tk_uid_lbl.pack()
tk_uid_lbl.place(x=20,y=20)
uid = StringVar()
tk_uid = Entry(mScrn, bd=3, textvariable=uid)
tk_uid.pack()
tk_uid.place(x=150, y=20)
tk_pwd_lbl = Label(mScrn, text="MVS1 Password")
tk_pwd_lbl.pack()
tk_pwd_lbl.place(x=20,y=60)
pwd = StringVar()
tk_pwd = Entry(mScrn, bd=3, show='*', textvariable=pwd)
tk_pwd.pack()
tk_pwd.place(x=150, y=60)
tk_ver_lbl = Label(mScrn, text="Version #")
tk_ver_lbl.pack()
tk_ver_lbl.place(x=20,y=100)
ver = StringVar()
tk_ver=Entry(mScrn, bd=3, textvariable=ver)
tk_ver.pack()
tk_ver.place(x=150, y=100)
tk_sub_button = Button(text='Submit', command = show_footer)
tk_sub_button.pack()
tk_sub_button.place(x=150, y=150)
mScrn.mainloop()
#The data provided in the GUI is used for access and a lot of process goes on
#Close the Tkinter window post the process is done
提前致谢。我正在使用 Python3
【问题讨论】:
-
我会在否决之前要求一个理由
-
问题是什么?您提供的代码如何相关或minimal reproducible example?
-
@sushant047 脚本执行完成后,就没有什么可做的了。您似乎知道如何关闭窗口以及如何添加标签,那么您的实际问题是什么?在打包后放置小部件对我来说没有意义,但这似乎与您的问题无关。
-
在关闭mainloop()之前不知道如何获取数据。在这方面,一旦关闭,我就无法在 GUI 上显示标签,然后在用户同意的情况下关闭(即在消息框中单击“确定”后)
标签: python python-3.x tkinter process