窗口关闭后,为什么不解密线程?

时间:2018-01-29 08:24:03

标签: python python-3.x tkinter

我有一个类ClientGUI(make in tkinter),它代表我的应用程序的客户端类。在此类中,按下按钮后,将打开一个新的tkinter窗口(使用我导入的模块),该窗口代表绘图工具的UI。当我关闭此绘图工具窗口时,我希望它向客户端类返回绘图工具已关闭的消息。问题是我只有在关闭主客户端窗口时才会收到此消息。所有这些的代码如下:

这是声明并启动主客户端窗口的代码:

root = Tk()
root.resizable(False, False)
root.title("Client")
root.protocol("WM_DELETE_WINDOW", onX)
clientGui = clientGUI(root) //clientGUI is the client class. It contains all the UI and functionality elements
root.mainloop()

这是我用来关闭它的功能:

def onX():
    answer = tkinter.messagebox.askquestion("Quit", "Are you sure you want to quit the application ?")

    if answer == "yes":
        root.destroy()

在clientGUI中,按下按钮后,将从我创建的模块打开一个新窗口,这是启动新窗口的代码:

def startDrawingTool(self, username, password):

    drawingToolStatus = drawingTool.startTool() // the new window is opened here
    print(drawingToolStatus) // This only gets printed when I close the main client window(clientGui)

这是startTool()函数,在我导入的drawingTool模块中声明:

def startTool():
    def onX():
        answer = tkinter.messagebox.askquestion("Quit", "Quiting without saving may result in data loss, make sure to always save first. Are you sure you want to quit?")
        if answer == "yes":
            root.destroy()

    root = Tk()
    root.resizable(False, False)
    root.title("Drawing program")
    root.protocol("WM_DELETE_WINDOW", onX)
    app = Application(root) // Application is the drawing tool class, contains all the UI elements and functionality
    root.mainloop()

    return "window closed" // This is how I want to let the main client class know that the drawing tool has been closed

希望我已经提供了所需的所有代码,以了解应用程序和我面临的问题。正如我已经说过的,我想知道为什么" print(drawingToolStatus)"仅在clientGui关闭时打印,并且只要我关闭drawingTool,就不会打印出来。

此外,如果您知道更好的方式进行两次沟通,我可以接受改进,因为这是我工作的第一个Python应用程序。

0 个答案:

没有答案