我正在尝试从另一个名为Add_user
的函数调用一个名为Edit_user_admin
的函数,我很确定我已经正确编写了所有内容,但我仍然遇到同样的错误。
File "G:/PVH_work/PVH_program/ParkTheReal.py", line 395, in <lambda>
Add_user = ttk.Button(frame_27, text="Add User", command=lambda: Add_user(frame_27, data_dictionary)).grid(row=1, column=0)
TypeError: 'NoneType' object is not callable
这是函数Edit_user_admin
:
def Edit_user_admin(form_item, data_dictionary, row_num):
form_item.grid_forget()
frame_27 = Frame(gui)
frame_27.grid()
MyProfile = ttk.Button(frame_27, text="My profile", command=lambda: My_profile_admin(frame_27, data_dictionary, row_num)).grid(row=0, column=0)
TrainingRecord = ttk.Button(frame_27, text="Training Record", command=lambda: Training_record_admin(frame_27, data_dictionary, row_num)).grid(row=0, column=1)
Compare = ttk.Button(frame_27, text="Compare", command=lambda: Compare_admin(frame_27, data_dictionary, row_num)).grid(row=0, column=2)
EditUsers = ttk.Button(frame_27, text="Edit Users", command=lambda: Edit_user_admin(frame_27, data_dictionary, row_num)).grid(row=0, column=3)
Team = ttk.Button(frame_27, text="View/Edit Team", command=lambda: Team_admin(frame_27, data_dictionary, row_num)).grid(row=0, column=4)
Logout = ttk.Button(frame_27, text="Logout", command=lambda: Logout(frame_27)).grid(row=0, column=5)
Add_user = ttk.Button(frame_27, text="Add User", command=lambda: Add_user(frame_27, data_dictionary, row_num)).grid(row=1, column=0)
Edit_user = ttk.Button(frame_27, text="Edit User", command=lambda: Edit_user(frame_27, data_dictionary, row_num)).grid(row=1, column=1)
Remove_user = ttk.Button(frame_27, text="Remove User", command=lambda: Remove_user(frame_27, data_dictionary, row_num)).grid(row=1, column=2)
这是函数Add_user
:
def Add_user(form_item, data_dictionary, row_num):
form_item.grid_forget()
frame_28 = Frame(gui)
frame_28.grid()
#Declare variables for creating a new user account
__Username = StringVar()
__Name = StringVar()
__Age = StringVar()
__Email = StringVar()
__DoB = StringVar()
MyProfile = ttk.Button(frame_28, text="My profile", command=lambda: My_profile_admin(frame_28, data_dictionary, row_num)).grid(row=0, column=0)
TrainingRecord = ttk.Button(frame_28, text="Training Record", command=lambda: Training_record_admin(frame_28, data_dictionary, row_num)).grid(row=0, column=1)
Compare = ttk.Button(frame_28, text="Compare", command=lambda: Compare_admin(frame_28, data_dictionary, row_num)).grid(row=0, column=2)
EditUsers = ttk.Button(frame_28, text="Edit Users", command=lambda: Edit_user_admin(frame_28, data_dictionary, row_num)).grid(row=0, column=3)
Team = ttk.Button(frame_28, text="View/Edit Team", command=lambda: Team_admin(frame_28, data_dictionary, row_num)).grid(row=0, column=4)
Logout = ttk.Button(frame_28, text="Logout", command=lambda: Logout_so(frame_28)).grid(row=0, column=5)
我在其他函数上遇到此错误,但我发现在我试图调用其名称的函数中添加了一个'_',然后在命令中添加了相同的名称扩展名。
答案 0 :(得分:3)
您已将None
分配给Add_user
; ttk.Button.grid()
返回None
:
Add_user = ttk.Button(...).grid(row=1, column=0)
你应该不使用相同的名称作为按钮参考和功能;在这种情况下,Python将使用局部变量,而不是全局函数。
使用其他名称,并分别致电.grid()
:
add_user_button = ttk.Button(
frame_27, text="Add User",
command=lambda: Add_user(frame_27, data_dictionary, row_num))
add_user_button.grid(row=1, column=0)
这同样适用于其他按钮。
但是,如果您没有在其他地方使用add_user_button
引用,则可以将其设为一行,但您不必为分配结果而烦恼:
ttk.Button(
frame_27, text="Add User",
command=lambda: Add_user(frame_27, data_dictionary, row_num)
).grid(row=1, column=0)