Import File Button in CustomTkinter #2519
Answered
by
dipeshSam
lorenzobandini
asked this question in
Q&A
-
hello everyone, |
Beta Was this translation helpful? Give feedback.
Answered by
dipeshSam
Jul 26, 2024
Replies: 1 comment 6 replies
-
Use import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd
from tkinter.messagebox import showinfo
from customtkinter import CTk, CTkButton
# create the root window
root = CTk()
root.title('Tkinter Open File Dialog')
root.resizable(False, False)
root.geometry('300x150')
def select_file():
filetypes = (
('text files', '*.txt'),
('All files', '*.*')
)
filename = fd.askopenfilename(
title='Open a file',
initialdir='/',
filetypes=filetypes)
showinfo(
title='Selected File',
message=filename
)
# open button
open_button = CTkButton(
root,
text='Open a File',
command=select_file
)
open_button.pack(expand=True)
# run the application
root.mainloop() |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
lorenzobandini
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
filedialog
by Tkinter. Here is sample code: