隐藏tk窗口并仅显示消息框

时间:2016-07-07 15:03:01

标签: python tkinter

如何仅显示消息框并隐藏tk模式窗口?如果有人可以在下面修改它,那就太好了。

import time
import Tkinter as tk
import tkMessageBox

root = tk.Tk()
root.withdraw

def timer(hours):
    seconds = hours * 60
    start = time.time()

    elapsed = 0
    while elapsed < seconds:

        time.sleep(0.0010)
        elapsed = time.time() - start

    elapsed = elapsed//60

    tkMessageBox.showinfo("Done", "Done Today" +str(elapsed) + " Hrs")

timer(1)

2 个答案:

答案 0 :(得分:0)

好吧,你几乎已经做到了......

root = tk.Tk()
root.withdraw()
timer(.1)
root.mainloop()

答案 1 :(得分:0)

您可以使用此方法。

import time
import Tkinter as tk

root = tk.Tk()
root.withdraw

def timer(hours):
    seconds = hours * 60
    start = time.time()

    elapsed = 0
    while elapsed < seconds:

        time.sleep(0.0010)
        elapsed = time.time() - start

    elapsed = elapsed//60

    #tkMessageBox.showinfo("Done", "Done Today" +str(elapsed) + " Hrs")
    root.title("Done")
    label = tk.Label(root, text= "Done Today " +str(elapsed) + " Hrs" )
    label.pack(side="top", fill="both", expand=True, padx=20, pady=20)
    button = tk.Button(root, text="OK", command=lambda: root.destroy())
    button.pack(side="bottom", fill="none", expand=True)
    root.mainloop()

timer(1)