tkinterを使ってファイル参照を行いたいのですが、zip fileを参照しようとファイルをクリックするだけで動作がフリーズしint32 型の値が大きすぎるか、または小さすぎです。とでます。調べたところ型に対して数値が大きいとなるそうですが、tkinterのファイル参照関数ではファイルの選択などに制限があるのでしょうか?どなたか知っている方がおりましたら、よろしくお願いします。
python
import os,sys from tkinter import * from tkinter import ttk from tkinter import messagebox from tkinter import filedialog # フォルダ指定の関数 def dirdialog_clicked(): iDir = os.path.abspath(os.path.dirname(__file__)) iDirPath = filedialog.askdirectory(initialdir = iDir) entry1.set(iDirPath) # ファイル指定の関数 def filedialog_clicked(): fTyp = [("", "*")] iFile = os.path.abspath(os.path.dirname(__file__)) iFilePath = filedialog.askopenfilename(filetype = fTyp, initialdir = iFile) entry2.set(iFilePath) # 実行ボタン押下時の実行関数 def conductMain(): text = "" dirPath = entry1.get() filePath = entry2.get() if dirPath: text += "フォルダパス:" + dirPath + "\n" if filePath: text += "ファイルパス:" + filePath if text: messagebox.showinfo("info", text) else: messagebox.showerror("error", "パスの指定がありません。") print(dirPath) if __name__ == "__main__": # rootの作成 root = Tk() root.title("サンプル") # Frame1の作成 frame1 = ttk.Frame(root, padding=10) frame1.grid(row=0, column=1, sticky=E) # 「フォルダ参照」ラベルの作成 IDirLabel = ttk.Label(frame1, text="展開先>>", padding=(5, 2)) IDirLabel.pack(side=LEFT) # 「フォルダ参照」エントリーの作成 entry1 = StringVar() IDirEntry = ttk.Entry(frame1, textvariable=entry1, width=30) IDirEntry.pack(side=LEFT) # 「フォルダ参照」ボタンの作成 IDirButton = ttk.Button(frame1, text="参照", command=dirdialog_clicked) IDirButton.pack(side=LEFT) # Frame2の作成 frame2 = ttk.Frame(root, padding=10) frame2.grid(row=2, column=1, sticky=E) # 「ファイル参照」ラベルの作成 IFileLabel = ttk.Label(frame2, text="展開元>>", padding=(5, 2)) IFileLabel.pack(side=LEFT) # 「ファイル参照」エントリーの作成 entry2 = StringVar() IFileEntry = ttk.Entry(frame2, textvariable=entry2, width=30) IFileEntry.pack(side=LEFT) # 「ファイル参照」ボタンの作成 IFileButton = ttk.Button(frame2, text="参照", command=filedialog_clicked) IFileButton.pack(side=LEFT) # Frame3の作成 frame3 = ttk.Frame(root, padding=10) frame3.grid(row=5,column=1,sticky=W) # 実行ボタンの設置 button1 = ttk.Button(frame3, text="実行", command=conductMain) button1.pack(fill = "x", padx=30, side = "left") # キャンセルボタンの設置 # button2 = ttk.Button(frame3, text=("閉じる"), command=quit) #button2.pack(fill = "x", padx=30, side = "left") root.mainloop()
まだ回答がついていません
会員登録して回答してみよう