open one tkinter file

Solutions on MaxInterview for open one tkinter file by the best coders in the world

showing results for - "open one tkinter file"
Lena
16 Aug 2020
1import tkinter as tk
2from tkinter import ttk
3from tkinter import filedialog as fd
4from tkinter.messagebox import showinfo
5
6# create the root window
7root = tk.Tk()
8root.title('Tkinter Open File Dialog')
9root.resizable(False, False)
10root.geometry('300x150')
11
12
13def select_file():
14    filetypes = (
15        ('text files', '*.txt'),
16        ('All files', '*.*')
17    )
18
19    filename = fd.askopenfilename(
20        title='Open a file',
21        initialdir='/',
22        filetypes=filetypes)
23
24    showinfo(
25        title='Selected File',
26        message=filename
27    )
28
29
30# open button
31open_button = ttk.Button(
32    root,
33    text='Open a File',
34    command=select_file
35)
36
37open_button.pack(expand=True)
38
39
40# run the application
41root.mainloop()
42Code language: Python (python)
similar questions
queries leading to this page
open one tkinter file