[英]tkinter Attribute error - Object has no attribute. I don't understand why it can't find the attribute of this object
[英]I can't understand some find_text function in Tkinter
我開始讀有關Tkinter的書
(Tkinter GUI應用程序開發藍圖)
當我開始在本書的幫助下創建文本編輯器時,我並沒有真正理解其中的一部分。
有一個功能可以幫助您在文本中查找單詞。
def find_text(event=None):
search_toplevel = Toplevel(root)
search_toplevel.title('Find Text')
search_toplevel.transient(root)
search_toplevel.resizable(False, False)
Label(search_toplevel, text="Find All:").grid(row=0, column=0, sticky='e')
search_entry_widget = Entry(
search_toplevel, width=25)
search_entry_widget.grid(row=0, column=1, padx=2, pady=2, sticky='we')
search_entry_widget.focus_set()
ignore_case_value = IntVar()
Checkbutton(search_toplevel, text='Ignore Case', variable=ignore_case_value).grid(
row=1, column=1, sticky='e', padx=2, pady=2)
Button(search_toplevel, text="Find All", underline=0,
command=lambda: search_output(
search_entry_widget.get(), ignore_case_value.get(),
content_text, search_toplevel, search_entry_widget)
).grid(row=0, column=2, sticky='e' + 'w', padx=2, pady=2)
對於我們來說很難創建按鈕的行。 我發現lambda函數和普通函數一樣,但是是以其他方式創建的,但是其他stufffff確實很困難。能否請您解釋一下這段代碼的實際作用? (按鈕代碼)
完整代碼:
也許它將幫助您將其視為正常功能寫出來。 該代碼也可以正常工作:
def find_clicked():
search_output(
search_entry_widget.get(), ignore_case_value.get(),
content_text, search_toplevel, search_entry_widget)
Button(search_toplevel, text="Find All", underline=0,
command=find_clicked).grid(row=0, column=2, sticky='e' + 'w', padx=2, pady=2)
lambda唯一適合的事情是將東西塞到一行上,從而使人們感到困惑。 我建議您盡可能避免使用lambda。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.