Skip to content

Import File Button in CustomTkinter #2519

Answered by dipeshSam
lorenzobandini asked this question in Q&A
Discussion options

You must be logged in to vote

Use filedialog by Tkinter. Here is sample code:

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,…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@dipeshSam
Comment options

@mahanmarwat
Comment options

@dipeshSam
Comment options

@mahanmarwat
Comment options

@dipeshSam
Comment options

Answer selected by lorenzobandini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants