Select file in dialog with python → Display file name in message box

ext_filename.py



sver='title'

#Module import
import os, tkinter, tkinter.filedialog, tkinter.messagebox

#Display file selection dialog
root = tkinter.Tk()
root.withdraw()
#File format specification. The second argument"*txt"given that
#Only files with the extension txt are displayed.
fTyp = [("*","*")]
iDir = os.path.abspath(os.path.dirname(__file__))
res=tkinter.messagebox.askyesno(sver, 'Select input parameter file. \nSuspend the process if you choose "No"')

#Error message is displayed by selecting Cancel
if res==True:
    file = tkinter.filedialog.askopenfilename(filetypes = fTyp,initialdir = iDir)
    
    if file=='':
        tkinter.messagebox.showerror(sver, "Suspend the process")        
    else:
        #Output of processing file name
        mess='Input file name is \n' + file
        #Message in the box
        tkinter.messagebox.showinfo(sver,mess)        

else:
    tkinter.messagebox.showerror(sver, "Suspend the process")

A screen like this is displayed ↓ test1.png

Recommended Posts

Select file in dialog with python → Display file name in message box
Exclusive control with lock file in Python
Display Python 3 in the browser with MAMP
Read table data in PDF file with Python
Extract zip with Python (Japanese file name support)
Open a file dialog with a python GUI (tkinter.filedialog)
File operations in Python
File processing in Python
Exception message in Python
File operations in Python
Run a Python file with relative import in PyCharm
Scraping with selenium in Python
Working with LibreOffice in Python
Download the file in Python
Display UTM-30LX data in Python
Debugging with pdb in Python
Draw netCDF file with python
[Python] Read the csv file and display the figure with matplotlib
Working with sounds in Python
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
Gacha written in Python -BOX gacha-
Easy password box in Python
Display Japanese in JSON file
Download csv file with python
Try to decipher the garbled attachment file name with Python
Get message from first offset with kafka consumer in python
Read a file in Python with a relative path from the program
How to display legend marks in one with Python 2D plot
Number recognition in images with Python
Extract the xz file with python
Testing with random numbers in Python
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
[Python] Write to csv file with Python
Save the binary file in Python
[Automation with python! ] Part 1: Setting file
Scraping with Selenium in Python (Basic)
Linebot creation & file sharing in Python
CSS parsing with cssutils in Python
Output to csv file with Python
Handle posix message queues in python
Numer0n with items made in Python
Create an Excel file with Python3
Create a binary file in Python
Waveform display of audio in Python
Display characters like AA in python
Use rospy with virtualenv in Python3
Use Python in pyenv with NeoVim
Heatmap with Dendrogram in Python + matplotlib
Read files in parallel with Python
Password generation in texto with python
Use OpenCV with Python 3 in Window
ORC, Parquet file operations in Python
[Automation with python! ] Part 2: File operation
Get the host name in Python
Until dealing with python in Atom
Get started with Python in Blender
Working with DICOM images in Python
Replace the directory name and the file name in the directory together with a Linux command.