如何杀死或破坏根窗口或子窗口

时间:2018-03-18 04:54:38

标签: python tkinter

import tkinter as tk
from tkinter import messagebox
import xlrd as rd

class Example():
    def __init__(self,master):
        self.frameExample =tk.Frame(master,width =600,height = 200)
        self.frameExample.pack()

        self.loadButton = tk.Button(self.frameExample,text = "Load",command =self.loadFile)
        self.loadButton.pack()


    def loadFile(self):
        sheetWindow = tk.Toplevel()
        sheetFrame = tk.Frame(sheetWindow, width = 600,height = 400,bg = "alice blue")        
        sheetFrame.pack()

        try:
            print("entered")
            self.workbook = rd.open_workbook("tiger.jpg")

        except:
            print("entered 1")
            messagebox.showinfo(title = "Load error",message = "Error")
            self.master.destroy()


root = tk.Tk()
Example(root)
root.mainloop()

我试过self.masterdestroy(),不确定如何杀死主窗口

1 个答案:

答案 0 :(得分:1)

只需将PersonName添加到您的self.master = master方法中,然后您的代码即可运行。