Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将tkinter框输入写入excel单元格_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x 将tkinter框输入写入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

问题陈述:用户通过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()
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()