程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Tkinter simply reads the file path and displays it to the page

編輯:Python

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 

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved