【问题标题】:I can not find a way to clear the window我找不到清除窗口的方法
【发布时间】:2018-09-23 22:35:24
【问题描述】:
import tkinter as tk

class main_window(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        win_button = tk.Button(self, text="Searching and sorting algorithms",
                               command=self.window)
        win_button.grid(column=1,row=1)

        win_button2 = tk.Button(self, text="BIG 0",
                               command=self.window)
        win_button2.grid(column=3,row=1)

        win_button3 = tk.Button(self, text="Tree Traversal",
                               command=self.window)
        win_button3.grid(column=1, row=3)

        win_button4 = tk.Button(self, text="profix,infix and prefix",
                               command=self.window)
        win_button4.grid(column=3, row=3)

    def all_children (wid) :
        _list = wid.winfo_children()

        for item in _list :
            if item.winfo_children() :
                _list.extend(item.winfo_children())

        return _list

    def clear(self):
        list= root.grid_slaves()
        for k in list:
            k.destroy()


    def window(self):
        self.clear()

if __name__ == "__main__":
    global root
    root = tk.Tk()
    main_window(root).pack(fill="both", expand=True)
    root.mainloop()

我正在尝试让它创建一个具有 4 个选项的屏幕。然后,该窗口将清除用户选择的任何一个并弹出新信息,但我无法清除。我努力了 。破坏,但它确实有效。

【问题讨论】:

标签: python tkinter python-3.6


【解决方案1】:

您的问题只是您正在调用root.grid_slaves,但直接在根目录中的唯一窗口由pack 管理,而不是grid。不要使用root.grid_slaves(),而是在clear 中使用self.grid_slaves()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-28
    • 2012-06-07
    • 2016-01-13
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多