|
发表于 2017-10-10 00:33:47
|
显示全部楼层
后台运行无非就是把窗口隐藏起来。要用的时候在显示出来
参考代码:
- import tkinter as Tk
-
- ########################################################################
- class MyApp(object):
- """"""
-
- #----------------------------------------------------------------------
- def __init__(self, parent):
- """Constructor"""
- self.root = parent
- self.root.title("Main frame")
- self.frame = Tk.Frame(parent)
- self.frame.pack()
-
- btn = Tk.Button(self.frame, text="Open Frame", command=self.openFrame)
- btn.pack()
-
- #----------------------------------------------------------------------
- def hide(self):
- """"""
- self.root.withdraw()
-
- #----------------------------------------------------------------------
- def openFrame(self):
- """"""
- self.hide()
- otherFrame = Tk.Toplevel()
- otherFrame.geometry("400x300")
- otherFrame.title("otherFrame")
- handler = lambda: self.onCloseOtherFrame(otherFrame)
- btn = Tk.Button(otherFrame, text="Close", command=handler)
- btn.pack()
-
- #----------------------------------------------------------------------
- def onCloseOtherFrame(self, otherFrame):
- """"""
- otherFrame.destroy()
- self.show()
-
- #----------------------------------------------------------------------
- def show(self):
- """"""
- self.root.update()
- self.root.deiconify()
-
-
- #----------------------------------------------------------------------
- if __name__ == "__main__":
- root = Tk.Tk()
- root.geometry("800x600")
- app = MyApp(root)
- root.mainloop()
复制代码 |
|