Python GUI open a file (filedialog) 📁

Поделиться
HTML-код
  • Опубликовано: 22 авг 2024

Комментарии • 77

  • @BroCodez
    @BroCodez  4 года назад +33

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

    • @vladglassofficial
      @vladglassofficial 3 года назад

      How to print variable "filepath" outside a function?

    • @sportiano3348
      @sportiano3348 2 года назад

      but i want create text editor and i want to from the user open file.txt to show on text editor ?
      any way to this

  • @EltonSenne
    @EltonSenne 2 года назад +12

    Simple and fast, exact what I need!

  • @vadzimfiadotsyeu2967
    @vadzimfiadotsyeu2967 2 года назад +4

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

  • @KhoaNguyen-bk2kv
    @KhoaNguyen-bk2kv 3 года назад +3

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

  • @nishadshivprakash
    @nishadshivprakash 3 года назад +4

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

  • @amirekhalili
    @amirekhalili 10 месяцев назад +1

    Thanks for simple explanation

  • @user-nk4hd2lx9z
    @user-nk4hd2lx9z Месяц назад

    hi i from of venezuela, nice video

  • @shahabkhokhar4039
    @shahabkhokhar4039 2 года назад

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

  • @digitalmachine0101
    @digitalmachine0101 5 месяцев назад

    Good information

  • @yosefgreen4187
    @yosefgreen4187 2 года назад +1

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

  • @Data_Falcon
    @Data_Falcon 3 месяца назад

    BRO YOUR VIDEOS IS SO USEFUL

  • @martin-xq7te
    @martin-xq7te 2 года назад

    Great short to the point tutorial. Thank you

  • @deepdaddy1208
    @deepdaddy1208 4 года назад +13

    great vid bro, im not a bot, just clarifying

  • @peromiracomodudan...6876
    @peromiracomodudan...6876 2 года назад

    Nice done

  • @exploretheuniverse1686
    @exploretheuniverse1686 4 месяца назад

    thank you .....keep it up

  • @piotrkopcewicz5227
    @piotrkopcewicz5227 Год назад

    Great tutorial. Love it !!:)

  • @user-tt7og8wf9h
    @user-tt7og8wf9h Год назад

    🥰🥰🥰🥰🥰🥰

  • @tanphatnguyen4873
    @tanphatnguyen4873 Год назад

    I got it. Thank you so much !

  • @anaschafik6109
    @anaschafik6109 Год назад

    this tutorial helped me , Thank you

  • @seifelshlkany5032
    @seifelshlkany5032 2 года назад

    Thank you very much! you are amazing

  • @davutselamiozkahraman8200
    @davutselamiozkahraman8200 11 месяцев назад

    Very good video

  • @chetanpatteparapu7600
    @chetanpatteparapu7600 3 года назад

    Thank you, this is helpful.

  • @AniruddhaGA
    @AniruddhaGA 3 года назад +5

    bad file type "*.txt", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"

  • @imamsantoso7994
    @imamsantoso7994 3 месяца назад

    Thank you

  • @martinrosschou
    @martinrosschou 7 дней назад

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

  • @rolfjohansen5376
    @rolfjohansen5376 Год назад +1

    RuntimeError: main thread is not in main loop

  • @JimmyZyzz
    @JimmyZyzz 3 года назад

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

  • @personanongrata2339
    @personanongrata2339 Год назад

    thank you so much

  • @KumarAnalytic
    @KumarAnalytic 2 года назад

    Great Video

  • @elijahdavis5120
    @elijahdavis5120 2 года назад

    nice

  • @mohamedtaki8748
    @mohamedtaki8748 2 года назад

    Thank you very much

  • @lovebaking2503
    @lovebaking2503 Год назад

    thanks for sharing the code

  • @jeremy_ching
    @jeremy_ching Год назад

    bu'on bu'on

  • @sonalivishwakarma9351
    @sonalivishwakarma9351 Год назад

    Thank you 🙂

  • @bjh5878
    @bjh5878 3 года назад

    Thank you !!

  • @EissaAlahdul
    @EissaAlahdul Год назад

    شكرا

  • @akashaabeysundara8454
    @akashaabeysundara8454 4 месяца назад

    thanks bro

  • @aneverdayhobbiest2837
    @aneverdayhobbiest2837 7 месяцев назад

    comment to help with algorithm.

  • @davidrose1999
    @davidrose1999 2 года назад

    Cool Video Cheers

  • @maxsuspochtam1489
    @maxsuspochtam1489 6 месяцев назад

    thank u

  • @hasansolak23
    @hasansolak23 3 года назад

    You gotta add those nuclear launch codes to the description too...

  • @user-jn7ev3qs9e
    @user-jn7ev3qs9e 3 года назад

    Как же прекрасно, что здесь есть субтитры на русском. Спасибо огромное!

    • @vladglassofficial
      @vladglassofficial 3 года назад

      Как мне получить доступ к переменной filepath, не объявляя её глобальной, и не вызывая функцию

    • @user-jn7ev3qs9e
      @user-jn7ev3qs9e 3 года назад

      @@vladglassofficial По сути в питоне переменные это ссылки. И если создать переменную в функции, и с тем же названием вне функции. Это будут разные переменные, отвечающие за разные участки памяти (но на вид тебе будут казаться одинаковыми). Если тебе нужно чтото делать с переменной после исполнения функции, то return (возврати то что тебе нужно). Если тебе вообще не хочется использовать функцию, то создай переменную в основном коде.
      Но я не совсем понимаю вопрос, т.к. не знаю зачем тебе это нужно.

  • @beingzero7541
    @beingzero7541 2 года назад

    Wow!!!!

  • @gustavoaponte1814
    @gustavoaponte1814 Год назад

    meow meow meow~!

  • @jhassee
    @jhassee Год назад

    loveIT

  • @user-kt1ec4zo6e
    @user-kt1ec4zo6e Год назад

    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 ?

  • @paraglide01
    @paraglide01 3 года назад

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

  • @KumarAnalytic
    @KumarAnalytic 2 года назад

    I subscribed you now

  • @tusharbhatriya3700
    @tusharbhatriya3700 3 года назад +1

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

  • @abdoularbi5718
    @abdoularbi5718 3 года назад

    thank you bro

  • @duyoan6821
    @duyoan6821 Год назад

    i was here

  • @loiczeq5551
    @loiczeq5551 2 года назад

    thanks :)

  • @bigdeallo
    @bigdeallo Год назад

    If you don't select a file and close the window. You get a FileNotFoundError

  • @AniGuy-sm7iy
    @AniGuy-sm7iy 2 года назад

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

  • @minhct2511
    @minhct2511 2 года назад

    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

  • @philtoa334
    @philtoa334 3 года назад

    My name is Pizza i like Bro. : )

  • @Artzaint
    @Artzaint 2 года назад

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

  • @naturesounds1427
    @naturesounds1427 3 года назад

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

  • @dwithidaya4168
    @dwithidaya4168 3 года назад

    Sir,
    How can I open a excel sheet within the created gui window

  • @wakkendul1434
    @wakkendul1434 3 года назад

    Bro how I want to write when I only need print file name and not the file path.. can u help me please..

  • @riyapalkar1178
    @riyapalkar1178 3 года назад

    How to add this open button to submenu and open it through submenu . Plzs help 🙏

  • @gwyne4192
    @gwyne4192 Год назад

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

  • @KEVINSURIEL
    @KEVINSURIEL 5 месяцев назад

    How about multi files

  • @umartahir2043
    @umartahir2043 3 года назад

    Great video!!! What if I want to upload it to SQLite

  • @promax1st
    @promax1st 2 года назад

    :)

  • @mohitjain1804
    @mohitjain1804 Год назад

    How we can save the image on click

  • @joelkafesu6757
    @joelkafesu6757 3 года назад

    how can i put a button on this GUI that run a .py script

  • @KenDedes94
    @KenDedes94 2 года назад

    Can Excel files works on Tkinter?

  • @seu_policial9463
    @seu_policial9463 4 месяца назад

    coment

  • @arpanshah355
    @arpanshah355 Год назад

    comment