0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pythonでダイアログでファイル選択→メッセージボックスにファイル名表示

Last updated at Posted at 2020-06-13
ext_filename.py

sver='title'

# モジュールのインポート
import os, tkinter, tkinter.filedialog, tkinter.messagebox

# ファイル選択ダイアログの表示
root = tkinter.Tk()
root.withdraw()
#ファイル形式指定.第2引数を"*txt"とすれば
#拡張子がtxtのファイルのみが表示される.
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"')

#キャンセル選択でエラーメッセージ表示
if res==True:
    file = tkinter.filedialog.askopenfilename(filetypes = fTyp,initialdir = iDir)
    
    if file=='':
        tkinter.messagebox.showerror(sver, "Suspend the process")        
    else:
        # 処理ファイル名の出力
        mess='Input file name is \n' + file
        # ボックス内メッセージ
        tkinter.messagebox.showinfo(sver,mess)        

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

こんな感じの画面が表示される↓
test1.png

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?