首页 > 解决方案 > 如何使用 GUI Tkinter 和 Pandas 在 Excel 中添加数据

问题描述

嗨,我想通过单击添加按钮将数据添加到 Excel 工作表。我正在将 tkinter 用于 GUI 和 pandas 以使用 excel。我尝试了 get() 方法从输入字段中获取数据并将其添加到 Excel 工作表中。但是我在excel表中看不到任何东西。请帮忙。我的代码如下。

============

from tkinter import *
import pandas as pd

def UpdateSheet():
   writer = pd.ExcelWriter("Match1.xlsx")
   var.get(writer)
   writer.save()

top2=Tk()
top2.geometry("800x800")


var = StringVar()


t2name = Label(top2, text="Team 2 name").place(x=20, y=30)

t2entry = Entry(top2, width=30,textvariable=var).place(x=100, y=30)

sbtbtn2 = Button(top2, text="Submit", activebackground='Orange', activeforeground='Black', 
command=UpdateSheet).place(x=100, y=500)

top2.mainloop()

标签: pythonpandastkinterprojectxlrd

解决方案


推荐阅读