Read txt Save reference after adding and modifying
# !/user/bin/env Python3
# -*- coding:utf-8 -*-
""" file:window.py.py create time:2019/6/27 14:54 author:Loong Xu desc: window create time:2022/7/4 author:njl """
import tkinter as tk
from tkinter import filedialog, dialog
import os
window = tk.Tk()
window.title(' Window title ') # title
window.geometry('500x300') # Window size
file_path = ''
file_text = ''
text1 = tk.Text(window, width=50, height=10, bg='orange', font=('Arial', 12))
text1.pack()
def open_file():
''' Open file :return:local_ '''
global file_path
global file_text
file_path = filedialog.askopenfilename(title=u' Select File ', initialdir=(os.path.expanduser('H:/')))
print(' Open file :', file_path)
if file_path is not None:
file_text = " The file path is :" + file_path
text1.insert('insert', file_text)
bt1 = tk.Button(window, text=' Open file ', width=15, height=2, command=open_file)
bt1.pack()
window.mainloop() # Show