[英]Python: <lambda> TypeError: 'NoneType' object is not callable
我正在嘗試從另一個名為Edit_user_admin
的函數調用一個名為Add_user
函數,我敢肯定我已經正確地編寫了所有內容,但是我仍然遇到相同的錯誤。
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)
我在其他函數上遇到了此錯誤,但是我發現在要嘗試調用其名稱的函數中添加了“ _”,然后將它們的擴展名添加到了該命令中。
您將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
引用,則可以將其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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.