我在这里有一个简单的gui输入按钮等,我试图从一个按钮上运行两个命令。当我运行我的代码时,一个更新字典的命令和一个写入文件的命令我得到一个错误说
NameError:name' writeToFile'没有定义。
我无法看到任何明显错过的东西,而且只有当我将两个功能调用到按钮时我才会尝试
def combine_funcs(*funcs):
def combined_func(*args, **kwargs):
for f in funcs:
f(*args, **kwargs)
return combined_func
self.testButton = Button(self, text = "test",
command = combine_funcs(commando, writeToFile))
但它也不喜欢这样,它说comine_funcs没有定义
任何帮助将不胜感激!
from tkinter import *
import csv
class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.output()
fL = {}
def commando(x, y):
fL.update({x:int(y)}) # Please note that these x and y vars are private to this function. They are not the x and y vars as defined below.
print(fL)
def writeToFile():
with open('WorkOrderLog.csv', 'w') as f:
w=csv.writer(f, quoting=csv.QUOTE_ALL)
#w.writerow("Name" + self.input1.get())
w.writerow(fL)
def output(self):
input_1 = StringVar() # Creating the variables that will get the user's input.
input_2 = StringVar()
Label(text='Name:').grid(row=0, column=0, padx=5,pady=5)
self.input1 = Entry(root, textvariable=input_1, width=10)
self.input1.grid(row=0, column=1,padx=5,pady=5)
Label(text='Age:').grid(row=1, column=0,padx=5,pady=5)
self.input2 = Entry(root, textvariable=input_2, width=10)
self.input2.grid(row=1, column=1,padx=5,pady=5)
self.b = Button(text="Two Functions", command=commando)
self.b.grid(row=4, column=4, padx=5, pady=5)
self.b.bind('<ButtonRelease-1>', command=writeToFile)
self.b.focus_force()
# self.b = Button(root, text='Submit', command=sequence(commando, writeToFile))
#self.b.grid(row=4, column=4,padx=5,pady=5)
if __name__ == "__main__":
root=Tk()
root.title('Auto Logger')
root.geometry('1000x100')
app=App(master=root)
app.mainloop()
root.mainloop()