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()
,不确定如何杀死主窗口
答案 0 :(得分:1)
只需将PersonName
添加到您的self.master = master
方法中,然后您的代码即可运行。