python tkinterで、ボタンを押すと、画像フォルダが表示され、選んで表示させるコードを書きたい
エラーコードは
Exception in Tkinter callback Traceback (most recent call last): File "/Users/shunsuke/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/tkinter/__init__.py", line 1699, in __call__ return self.func(*args) File "tk3.py", line 16, in DeleteEntryValue dir_= tkinter.filedialog.askopenfilename() AttributeError: module 'tkinter' has no attribute 'filedialog'
なにがおかしいか教えて頂けないでしょうか?
下記コードです。
```import sys import tkinter from PIL import Image, ImageTk root = tkinter.Tk() root.title(u"Software Title") root.geometry("400x300") # ボタンが押されるとここが呼び出される # def DeleteEntryValue(event): root = tkinter.Tk() root.withdraw() dir_= tkinter.filedialog.askopenfilename() print(dir_) root.destroy() root = tkinter.Tk() photo = ImageTk.PhotoImage(Image.open(dir_)) labimg = tkinter.Label(root, image=photo) labimg.image = photo labimg.pack() #ボタン Button = tkinter.Button(text=u'ボタンです', width=50) Button.bind("<Button-1>",DeleteEntryValue) #左クリック(<Button-1>)されると,DeleteEntryValue関数を呼び出すようにバインド Button.pack() root.mainloop()
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/23 07:22
2017/11/23 07:39
2017/11/23 07:41
2017/11/23 07:46
2019/10/08 05:02