Open Files Dialog Box - Python Tkinter GUI Tutorial #15

Open Files Dialog Box - Python Tkinter GUI Tutorial #15

Codemy.com

5 лет назад

189,034 Просмотров

How to use Open Files Dialog Box in Tkinter and Python. In this video I'll show you how to open files with the filedialog box:

root.filename = filedialog.askopenfilename(initialdir="/", title="Select A File", filetypes=(("jpg files", "*.jpg"),("all files", "*.*")))

In this series I'll show you how to create graphical user interfaces for Python with Tkinter.

✅ Watch The Other Videos In This Python Playlist:
http://bit.ly/2UFLKgj


▶️ See More At:
https://Codemy.com


✅ Join My Facebook Group:
http://bit.ly/2GFmOBz


✅ Subscribe To My YouTube Channel:
http://bit.ly/2IGzvOR


▶️ Learn to Code at https://Codemy.com
Take $22 off with coupon code: youtube

Тэги:

#python #tkinter #gui #python_tkinter #tkinter_python #python_gui #tkinter_gui #gui_python #graphical_user_interfaces_python #tkinter_grid_system #grid_system_tkinter #python_grid_system #build_graphical_user_interfaces_with_python #how_to_build_graphical_user_interfaces_with_python #how_to_python_tkinter #open_file_dialog_python
Ссылки и html тэги не поддерживаются


Комментарии:

Barry Kruyssen
Barry Kruyssen - 05.09.2023 08:35

Great tutorial. I take it the filedialog just calls the OS's dialog box (which in linux on a chromebook is very lame)

Ответить
DARKxDANI
DARKxDANI - 21.08.2023 10:08

Thanks Sir I'm Your Student From Pakistan ❤i Subscribe Your Channel and Always Watching Your Videos , I Can't Afford ur Paid Courses On Web So I'm Wathcing u on YT

Ответить
陳文俊
陳文俊 - 26.06.2023 10:41

Straight to the problem, I love it

Ответить
VIP GAMER
VIP GAMER - 22.06.2023 14:12

Sir I added a file dialogue on a top-level but it does not show on the top but file dialogue shows under the top-level how can I fix this sir

Ответить
2noiembrie83
2noiembrie83 - 29.05.2023 15:53

Loved every minute of it!

Ответить
Peter Panagiotou
Peter Panagiotou - 27.04.2023 12:56

Hello, i would like to make a question. When you open the file you want, how can you make the button disappear from the "new" window that show the photo? Thanks in advance...

Ответить
The Genetic House - Brian Aston
The Genetic House - Brian Aston - 12.04.2023 11:12

Perfect I need this one for my app! Thanks again 4 hours in lol

Ответить
Eduardo Murphy Pérez
Eduardo Murphy Pérez - 30.01.2023 19:28

I was realizing that you need to use "from tkinter import filedialog" to make this script work... But I thought that "from tkinter import *" meant that it was already importing everything... Can somebody explain?

Ответить
Paul M
Paul M - 16.12.2022 14:15

Hello John,
I just payed the insanely low price for total membership :)

Ответить
Maxwell Hawk
Maxwell Hawk - 14.12.2022 23:37

im not clear with a import thing. First we do from tkinter import * it should import everything right? yet we specifically write from tkinter import filedialog, why?

Ответить
C0PPERM0NK
C0PPERM0NK - 05.12.2022 02:03

Fantastic tutorial thank you

Ответить
Refnom95
Refnom95 - 20.09.2022 16:25

Thanks for the great videos! Would be very grateful if you could answer a quick question?

What is the reason for assigning the file path string to 'root.filename'? From what I understand, this creates a new attribute called 'filename' for the 'root' object. What is the advantage of doing this instead of just assigning it to a normal variable (ie. just 'filename')?

Ответить
Priya Bharanidharan
Priya Bharanidharan - 11.09.2022 15:57

Im a beginner. Your vides are very helpful and resourceful for learning I tried this, but Im getting an error while assigning it to label.image

player=ImageTk.PhotoImage(Image.open(main.file_name))
player_pic=Label(main,image=main.file_name)


_tkinter.TclError: image "C:/Users/PD/messi.png" doesn't exist.

Can you please help me in this

Ответить
Omega33
Omega33 - 29.08.2022 23:34

You have the best channel on the internet. The way you teach is unprecedented the scope of these projects make students want to learn the boring theory in textbooks because its being applied in real time w/ real world application. Thank you.

Ответить
Алексей Соков
Алексей Соков - 03.07.2022 11:54

2022

Ответить
PetitFrapo
PetitFrapo - 18.06.2022 11:29

That photo with your dog is literally the brand image of the playlist, gotta love how cute your dog is!!

Ответить
dxbryakxff
dxbryakxff - 10.06.2022 01:53

MAN I LOVE U SO MUCH

Ответить
Ahmed Reda Saeed
Ahmed Reda Saeed - 14.05.2022 14:06

Thanks alot

Ответить
Ertuğrul Sırt
Ertuğrul Sırt - 02.04.2022 19:12

Is there a way to ask for file directory rather than a file, my program freezes when I try askdirectory()

Ответить
Funny Clips
Funny Clips - 27.02.2022 22:47

Excellent...! pls can this be done using grid() method ?

Ответить
tieuwest
tieuwest - 09.02.2022 10:16

Thanks. I really enjoy this and find this super helpful.

Ответить
Furrane
Furrane - 26.01.2022 09:44

FYI : the Scale command argument will pass the scale value to the function called. Which means you could use something like this here :

def slide(val):
root.geometry(str(val)+'x400')

Ответить
Slobodan Zlatanovic
Slobodan Zlatanovic - 08.12.2021 18:30

Thank you very much! that helped me!

Ответить
Victor Wang
Victor Wang - 09.11.2021 18:03

Why does the message pop up as '<io.TestIOWrapper name='xxx' mode='r' encoding='cp936'> after running my_label? Would you please help me to solve this problem?

Ответить
Moneeb K
Moneeb K - 01.11.2021 20:02

I don’t know why but my filter ain’t working. All the filetypes I give are applied automatically and then I cannot select any filetype.
They automatically apply all types.

Ответить
Totolariflette
Totolariflette - 20.10.2021 22:25

Thank you so much, you saved my day <3

Ответить
NAMAN ALLAWADHI
NAMAN ALLAWADHI - 17.09.2021 14:36

thank you Heisenberg :)

Ответить
Running Forver
Running Forver - 07.09.2021 14:36

I thought "from module import *" already imports everything there is in the module?
Why do we have to do from tkinter import textdialog after?

Ответить
la mlya
la mlya - 28.08.2021 14:14

You've just save a life 😉

Ответить
isuruprasad dilhara
isuruprasad dilhara - 22.08.2021 08:49

Best tutorial I have ever seen ❤

Ответить
Dylan Campbell
Dylan Campbell - 20.08.2021 02:24

I had no idea about filedialogs before this video, WOW. I have just been manually iterating through folders this entire time :( best video by far.

Ответить
Minh Hoàng Nhật
Minh Hoàng Nhật - 23.06.2021 18:43

Thanks for your videos

Ответить
Adnan Zareef
Adnan Zareef - 07.06.2021 14:23

Thanks sir! you just saved my day

Ответить
Dhruv Shah
Dhruv Shah - 05.06.2021 00:58

I'm on Mac and it is not working it is grayed out

Ответить
Bhuvan Girish Desai
Bhuvan Girish Desai - 29.05.2021 17:22

can we open a excel files??

Ответить
TIBBERS
TIBBERS - 25.05.2021 19:34

How come when I run this no button appears in the window?

Ответить
Hashmat Ali Shah
Hashmat Ali Shah - 24.05.2021 23:03

Sir this is my code(
from tkinter import *
from PIL import ImageTk,Image
from tkinter import filedialog

root = Tk()
root.title("Upload Image")

def open():
global my_image
root.filename = filedialog.askopenfilename(initialdir="/",title="Select A File", filetype=(("png files", "*.png"),("jpeg files", "*.jpg"),("jpng files", "*.jpng")))
my_label = Label(root,text=root.filename).pack()
my_image = ImageTk.PhotoImage(Image.open(root.filename))
my_image_label = Label(image=my_image).pack()

Button(root,text="Upload Image",command=open).pack()

root.mainloop()
)
two button should be display Open and cancel if i will not select any image and press Cancel button then this error should be display kindly solve this error.( fp = io.BytesIO(fp.read())
AttributeError: 'str' object has no attribute 'read')

Ответить
Myth
Myth - 23.05.2021 23:16

Pls anyone reply...how can i return the file path to a Entry box or feature or whatever u called....is it doable or we can only return it to a Label?

Ответить
Infinite Space
Infinite Space - 22.05.2021 22:48

I need some help, when I try to open multiple images, some of them are just blank. What is the reason for this? Is there a way to fix this?

Ответить
Deven Jain
Deven Jain - 18.05.2021 16:12

How to open a folder in file dialog instead of "All Files"

Ответить
Shreyash Choudhary
Shreyash Choudhary - 18.05.2021 10:32

Great! Really Helpful

Ответить
2.A.M.G
2.A.M.G - 04.05.2021 10:22

Hello, what if now i wanna open multiple images and show them all? If i choose all files, the FileName = filedialog.askopenfilename will become a list?

Ответить
KELLY MARTIN 1760625
KELLY MARTIN 1760625 - 09.04.2021 09:47

will no one mention the fact that aspen is so cute!

Ответить
Neha Yadav
Neha Yadav - 07.04.2021 18:51

I can't open mp4 files using this. is there any other way to do it?

Ответить
Riya Palkar
Riya Palkar - 06.04.2021 18:41

Thanku Sooo much . For this
I hadn't seen this video
Sorry . For that
But a big thanku this video helped me solve my problem 😊

Ответить