Python 3.x 将tkinter框输入写入excel单元格
问题陈述:用户通过tkinter框输入的内容未写入excel工作表 我的主要问题是.get()语句。我只想在excel上打印用户输入,而不考虑输入类型 提前谢谢Python 3.x 将tkinter框输入写入excel单元格,python-3.x,tkinter,Python 3.x,Tkinter,问题陈述:用户通过tkinter框输入的内容未写入excel工作表 我的主要问题是.get()语句。我只想在excel上打印用户输入,而不考虑输入类型 提前谢谢 from tkinter import * # define this function to close the window after text submition def close_window(): window.destroy() #window dimentions window = Tk() wind
from tkinter import *
# define this function to close the window after text submition
def close_window():
window.destroy()
#window dimentions
window = Tk()
window.title("My App")
window.geometry('350x200')
v = StringVar()
user_data = Entry(textvariable=v)
user_data.pack()
ans = v.get()
# I need this input on excel
f= open('sht.csv','w')
f.write(ans)
f.close()
button = Button(text="Submit", command = close_window)
button.pack()
window.mainloop()
因为您调用了close\u window函数,所以尝试一下这个,我添加了write\u函数。 无论如何,我建议采用面向对象的方法
from tkinter import *
# define this function to close the window after text submition
def close_window():
window.destroy()
#window dimentions
window = Tk()
window.title("My App")
window.geometry('350x200')
v = StringVar()
user_data = Entry(textvariable=v)
user_data.pack()
# I need this input on excel
def write_to():
ans = v.get()
f= open('sht.csv','w')
print(ans)
f.write(ans)
f.close()
button = Button(text="Submit", command = write_to)
button.pack()
window.mainloop()
因为您调用了close\u window函数,所以尝试一下这个,我添加了write\u函数。 无论如何,我建议采用面向对象的方法
from tkinter import *
# define this function to close the window after text submition
def close_window():
window.destroy()
#window dimentions
window = Tk()
window.title("My App")
window.geometry('350x200')
v = StringVar()
user_data = Entry(textvariable=v)
user_data.pack()
# I need this input on excel
def write_to():
ans = v.get()
f= open('sht.csv','w')
print(ans)
f.write(ans)
f.close()
button = Button(text="Submit", command = write_to)
button.pack()
window.mainloop()