我似乎無法將 ScrolledText Widget 的內(nèi)容打印到控制臺。我已在 ScrolledText 小部件上運行幫助命令:print(help(scrolledtext.ScrolledText))這輸出表明 .get 方法(用于獲取 tk.Text Widgets 的內(nèi)容)也存在于該小部件中。 | get(self, index1, index2=None) | Return the text from INDEX1 to INDEX2 (not included).那么為什么會出現(xiàn)這樣的行:print(myScrollTextWidget.get("1.0","end"))結(jié)果出現(xiàn)此錯誤:AttributeError: 'NoneType' object has no attribute 'get'當按鈕被按下時。這是我正在使用的可運行代碼片段:import tkinter as tkfrom tkinter import scrolledtext#Declare Rootroot = tk.Tk()root.title("Scrolltext Widget")tk.Label(root,text="My Scrolled Text Widget",font=("Times New Roman",25))\ .grid(row=0,column=1)#Define ScrollTextWidget#wrap keyword used to wrap around textmyScrollTextWidget = scrolledtext.ScrolledText(root,wrap=tk.WORD,width=50,height=20,font=("Times New Roman",15))\ .grid(row=1,column=1)print(help(scrolledtext.ScrolledText))def printToConsole(): print(myScrollTextWidget.get("1.0","end"))#ButtonsmyButton = tk.Button(root,text="Print to console!",command=printToConsole).grid(row=2,column=1)root.mainloop()
tkinter scrolledtext.ScrolledText 沒有 get 屬性
HUH函數(shù)
2023-09-19 17:39:24