我想知道是否可以将文本框中的文本转换为变量(/string)。
我使用的是Python3.3.5,我看到了很多Entrybox to variable,但它在文本框上不起作用。
下面是我正在使用的代码:from tkinter import *
main = Tk()
sr=Scrollbar(main)
a="Hello!"
txtBox = Text(main, width=20, height=5)
sr.pack(side=RIGHT)
txtBox.pack(side=LEFT)
sr.config(command=txtBox.yview)
txtBox.config(yscrollcommand=sr.set)
txtBox.insert(END, a)
def callback():
#here is the text converted to a variabel#
def closewindow():
exit()
def save():
key = #variabel#
f = open("key.txt", "w")
f.write(key)
f.close()
print(txtBox.get()+(" /has bin saved."))
button_dsp = Button(main, text="display text", width=10, command=callback)
button_dsp.pack()
button_save = Button(main, text="Save", width=10, command=save)
button_save.pack()
button_exit = Button(main, text="Exit", width=10, command=closewindow)
button_exit.pack()
mainloop()