Python GUI open a file (filedialog)

74 Views
Published
Python GUI filedialog tkinter open a file tutorial for beginners

#Python #GUI #filedialog #tkinter #open #file #tutorial #beginners

from tkinter import *
from tkinter import filedialog

def openFile():
filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main",
title="Open file okay?",
filetypes= (("text files","*.txt"),
("all files","*.*")))
file = open(filepath,'r')
print(file.read())
file.close()

window = Tk()
button = Button(text="Open",command=openFile)
button.pack()
window.mainloop()
Category
Bro Code
Tags
python, tkinter, gui
Be the first to comment