我创建了一个小程序来获取用户输入的文本并将文本保存在html文件中。这是我的小程序示例。在from tkinter import *
from jinja2 import Template
root=Tk()
textBox=Text(root, height=2, width=10)
textBox.pack()
buttonSave=Button(root, height=1, width=10, text="Save",
command=lambda: createCaseDetails())
buttonSave.pack()
def createCaseDetails():
# Create The template html for case report
t = Template("""
Case Report<Evidence> System Information
Created with love by bluebear119
Case Description
{{Case_Description}
""")
f = open('Case Report.html', 'w')
inputvalue = textBox.get("1.0", "end-1c")
print(inputvalue)
message = t.render(Case_Description=inputvalue)
f.write(message)
f.close()
print("Case Report.html file saved.")
mainloop()
但是当我在我的大量代码中实现这个时,我不能使用这个变量,因为它来自同一个类,而是在另一个函数的变量中。
我在顶层定义了createCaseDetails()函数,但我的文本框在另一个函数中,button也在另一个函数中。我如何按下按钮,并保存html格式的案例描述文本。在
文本框和按钮将在同一个类中定义如下:
^{pr2}$
错误是不能在createCaseDetails()函数中使用变量Case_Description_text。在