Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Last active June 8, 2024 20:49
Show Gist options
  • Save vigilantPotato/828862512ea877d22cd89388327df7f1 to your computer and use it in GitHub Desktop.
Save vigilantPotato/828862512ea877d22cd89388327df7f1 to your computer and use it in GitHub Desktop.
How to use filedialog_1
import ctypes
import tkinter, tkinter.filedialog
def get_filepath():
filepath = tkinter.filedialog.askopenfilename(
title="slect txt file",
filetypes=[("txt files", "*.txt")],
)
filepath_result["text"] = filepath
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
#message to show filepath
filepath_result = tkinter.Message(
root,
bg="lightblue"
)
filepath_result.pack()
#filedialog button
open_filedialog_button = tkinter.Button(
root,
bg="cyan",
command=get_filepath,
text="file select",
width=15,
)
open_filedialog_button.pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment