直接上代码
import xlwings as xw
from mytkinter import *
window = tk.Tk()
window.title('测试窗口')
window.geometry('500x300')
class Oc():
def __init__(self):
self.app=xw.App(visible=True,add_book=False)
def open_excel(self):
filepath=get_path()
wb=self.app.books.open(filepath)
def close_excel(self):
wb=xw.books.active
wb.close()
oc=Oc()
b=tk.Button(window,text='打开工作簿',width=10,
height=2,command=oc.open_excel)
b.pack(side=tk.TOP)
b1=tk.Button(window,text='关闭工作簿',width=10,height=2,command=oc.close_excel)
b1.pack(side=tk.TOP)
window.mainloop()
原来button的command后面不仅可以放函数,还可以放实例的方法,打通了这个环节,就为GUI编程打通的道路。