错误日志:
file_path = f_name.get()
AttributeError: 'NoneType' object has no attribute 'get'
代码:
f_name = tkinter.Entry().pack(side='left', expand=True, fill='both')
应该定义和布局进行分开:
f_name = tkinter.Entry() f_name.pack(side='left', expand=True, fill='both')
简单的gui文本编辑器学习代码:
import tkinter from tkinter.scrolledtext import ScrolledText top = tkinter.Tk() top.title('FileAction') def load(): file_path = f_name.get() print(file_path) with open(file_path, 'r', encoding='utf-8')as f: text.delete(0.0, 'end') text.insert('insert', f.read()) def save(): file_path = f_name.get() print(file_path) with open(file_path, 'w', encoding='utf-8')as f: f.write(text.get('1.0',