Python GUI open a file (filedialog) 📁

preview_player
Показать описание
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():
title="Open file okay?",
filetypes= (("text files","*.txt"),
("all files","*.*")))
file = open(filepath,'r')

window = Tk()
button = Button(text="Open",command=openFile)
Рекомендации по теме
Комментарии
Автор

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()

BroCodez
Автор

If you have errors about bad file type - use the following construction: filetypes=[("Text files", "*.txt"), ("Rulename", "file_extension")]

Pelmen
Автор

"hey you yeah i'm talking to you".
A useful video, thanks bro.

KhoaNguyen-bkkv
Автор

Awesome ◉‿◉. Explain good to understand. And thanks for sharing code in description. As I am new, this video is very helpful for me.

nishadshivprakash
Автор

I said fantastic before I see you video Sir! Because I know your teachings❤❤❤❤

kingshahzad
Автор

Great short to the point tutorial. Thank you

martin-xqte
Автор

what I like most is that you put the snippet code just in the description, thanks!

// a better easy solution to open file from dialog and close it after choosing the file:
from tkinter import *
from tkinter.filedialog import askopenfilename

root = Tk()
root.withdraw()
file_path = askopenfilename()
root.destroy()

yosefgreen
Автор

thank you so much! this is exactly what I needed! subscribed

shahabkhokhar
Автор

Thanks man, do know if a filepicker is in python?

paraglide
Автор

great vid bro, im not a bot, just clarifying

deepdaddy
Автор

RuntimeError: main thread is not in main loop

rolfjohansen
Автор

I'm about 2 hours in to my Python learning.
I removed all the button stuff, and just did openFile() instead.

martinrosschou
Автор

Bro if I want to show that txt or any file inside gui then what I can write?

tusharbhatriya
Автор

Excelente vídeo! Me sirvió de mucho. Saludos

JimmyZyzz
Автор

hey bro, why didn't you type the "master" when making the open button ?

AniGuy-smiy
Автор

Can you pls show me what I have to do if I want to show the text in the black window when I opened file

minhct
Автор

Is it possible to open multiple files and return multiple directories?

gwyne
Автор

How did you add the open menu with tkinter sign on your pycharm menu am confused, plz help

naturesounds
Автор

Hello Sir,
How to make a copy paste file when i make file name textbox then search file in network drive path and paste user destination path to set how to do this ?

KimPrajapati-fd
Автор

Awesome video, but what if i want to print it on a Textbox?

Artzaint