質問
tkinterを用いて画像をリサイズするプログラムを作ったのですが、実行するとウィジェットも何も表示されない状態です。
busy状態でエラーも何も表示されないので困っています。
何が間違っているのかご教示いただけると幸いです。
よろしくお願いいたします。
コード
python
1import os 2from tkinter import ttk 3#from tkinter import * 4#from tkinter.ttk import * 5from tkinter import filedialog 6from tkinter import messagebox 7from PIL import Image 8 9def indialog_clicked(): 10 iDir = os.path.abspath(os.path.dirname('__file__')) 11 in_dir = tkinter.filedialog.askdirectory(initialdir=iDir) 12 entry1.set(in_dir) 13 14def outdialog_clicked(): 15 iDir = os.path.abspath(os.path.dirname('__file__')) 16 out_dir = tkinter.filedialog.askdirectory(initialdir=iDir) 17 entry2.set(out_dir) 18 19def conductMain(): 20 inpath = entry1.get() 21 outpath = entry2.get() 22 23 files = os.listdir(inpath) 24 25 for file in files: 26 img = Image.open(os.path.join(inpath, file)) 27 #画像のパスを生成し、imgへ画像を格納 28 img_resize = img.resize((1080, 720)) 29 #imgへ格納した画像を720×1080サイズ変更 30 img_resize.save(os.path.join(outpath, file)) 31 32if __name__ == "__main__": 33 root = Tk() 34 root.withdraw() 35 root.title("image Resize") 36 root.geometry("400x300") 37 38 frame1 = ttk.Frame(root, padding=10) 39 frame1.grid(row=0,column=1,sticky=E) 40 41 inLabel = ttk.Label(frame1,text="読込フォルダ指定", padding=(5,2)) 42 inLabel.pack(side=LEFT) 43 44 # 「フォルダ参照」エントリーの作成 45 entry1 = StringVar() 46 IDirEntry = ttk.Entry(frame1, textvariable=entry1, width=30) 47 IDirEntry.pack(side=LEFT) 48 49 # 「フォルダ参照」ボタンの作成 50 IDirButton = ttk.Button(frame1, text="参照", command=indialog_clicked) 51 IDirButton.pack(side=LEFT) 52 53 # Frame2の作成 54 frame2 = ttk.Frame(root, padding=10) 55 frame2.grid(row=2, column=1, sticky=E) 56 57 # 「ファイル参照」ラベルの作成 58 outLabel = ttk.Label(frame2, text="書出フォルダ指定", padding=(5, 2)) 59 outLabel.pack(side=LEFT) 60 61 # 「ファイル参照」エントリーの作成 62 entry2 = StringVar() 63 IFileEntry = ttk.Entry(frame2, textvariable=entry2, width=30) 64 IFileEntry.pack(side=LEFT) 65 66 # 「ファイル参照」ボタンの作成 67 IFileButton = ttk.Button(frame2, text="参照", command=outdialog_clicked) 68 IFileButton.pack(side=LEFT) 69 70 # Frame3の作成 71 frame3 = ttk.Frame(root, padding=10) 72 frame3.grid(row=5,column=1,sticky=W) 73 74 # 実行ボタンの設置 75 button1 = ttk.Button(frame3, text="実行", command=conductMain) 76 button1.pack(fill = "x", padx=30, side = "left") 77 78 # キャンセルボタンの設置 79 button2 = ttk.Button(frame3, text=("閉じる"), command=quit) 80 button2.pack(fill = "x", padx=30, side = "left") 81 82 83 root.mainloop()
回答1件
あなたの回答
tips
プレビュー