Python GUI save a file (filedialog) 💾

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

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

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

    from tkinter import *
    from tkinter import filedialog
    def saveFile():
    file = filedialog.asksaveasfile(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main",
    defaultextension='.txt',
    filetypes=[
    ("Text file",".txt"),
    ("HTML file", ".html"),
    ("All files", ".*"),
    ])
    if file is None:
    return
    filetext = str(text.get(1.0,END))
    #filetext = input("Enter some text I guess: ") //use this if you want to use console window
    file.write(filetext)
    file.close()
    window = Tk()
    button = Button(text='save',command=saveFile)
    button.pack()
    text = Text(window)
    text.pack()
    window.mainloop()

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

      Thank you :)

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

      Tq but i m curious about another thing.
      Suppose we have an output already in tkinter window when we run a code so i want exactly same that is in tkinter window to download as a file instead of taking input from user and saving as a gile

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

      Is there a way?

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

      only a real Bro leaves the code in the comments and description, thanks!

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

    I'm developing a tool in my job and this tutorial helped me a LOOOOT. Thank you!

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

    Already liked and subscribed, Commenting now to keep this channel running. Lets beat the algorithm Broooooooooooooooooooooo

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

    Thanks alot for this simple and effective explaination

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

      thanks for watching Sanket!

  • @rafy-ivanmorales3077
    @rafy-ivanmorales3077 2 года назад

    Rafy-Ivan Morales
    0 seconds ago
    I'm a new student trying to learn, so I can become a programmer with python and I have a project on how to make a port scan.
    So far I already make a port scan with Python3, and it scans fine, give a date and everything working good so far.
    I see on your video tutorial you give example on how to send and receiving data.
    I would like to ask for your advice if you can and guide me on how I will add this 3
    in a Python script, I have:
    2. System should look for all the ports between the range of 1 to 1025
    3. If the Ports is open, it should create a file and add an entry for port number
    4. In case of any exception for instance “host is not available”, “host name could not be resolved” or
    due to any other error, you need to write that exception into the same file.
    Thank you and Merry Christmas.

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

    Such a nice tutorial ❤

  • @johnsonmcdonald292
    @johnsonmcdonald292 3 года назад +2

    Appreciate this. Thanks a lot!

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

    Nice video

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

    This video is great!!

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

    Great video......as usual!

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

    nice, 3 steps done

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

    Thank you once again Bro!

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

    Very awesome tutorial, thank you! :3
    but why do you have a folder named nuclear launch co...

  • @Sirbozo
    @Sirbozo 4 месяца назад +3

    why not any one see and comment the nuclear launch codes???? XD

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

    It very useful for me

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

    thank you very much

  • @ОГУРЕЦ-ч2д
    @ОГУРЕЦ-ч2д 4 года назад +1

    thank you for this video ,(there is little information about gui in Russia)

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

      Да я знаю, но есть несколько капелек.

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

    Nah bro is a national threat, packing nuclear codes like that😂😂

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

    Wow!!!!

  • @joshtornquist1937
    @joshtornquist1937 4 года назад +1

    hey bro, can you give me some advice? My program (1) fetches files from a website and (2) saves it to a folder on the user's computer. The problem is that within the code the user would have to copy down the directory path each time. I'm trying to find a way to (1) open the dialog box and (2) allow the user to choose where those files--the files the program will fetch--will be saved to, and then (3) let the program save the files to the newly chosen file location. Thank you! Also sorry if this isn't well explained. New to coding.

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

      sorry I'm not sure I understand. Do you mean such as having a default file location set up to read/write files to?

    • @joshtornquist1937
      @joshtornquist1937 4 года назад

      ​@@BroCodez Sort of. Again, pretty new to coding so I apologize.
      Let me try again . . .
      So right now, in my code, in order for some scraped files to be stored, I have to copy and paste the directory:
      edgar.download_index( *'/Users/josht/Desktop/EDGAR'* , 2018,skip_all_present_except_last=False)
      I'm trying to utilize the file dialog so that someone using this program can choose where to have those scraped files saved. In turn, this would automatically paste the directory chosen by the user in that line of code shown above.
      The result: _Open File Dialog > Choose Location > File Path Pasted Into Code > Code Continues_
      I hope that's a little bit better explained than before.
      Thanks bro!

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

      I see, this might work:
      after using file dialog, you could get the file location with file.name to return the file path, or even store it in a separate string variable.
      #*************************************
      def saveFile():
      file = filedialog.asksaveasfile()
      file_location = file.name
      #*************************************
      edgar.download_index( file_location, 2018,skip_all_present_except_last=False)

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

    thank you bro

  • @vinayaknayak5480
    @vinayaknayak5480 3 года назад +3

    Hi bro..need ur help..
    How can I save the processed image to a folder using tkinter?I mean how can I take any image as an input in this code..plz help

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

      heres some code for you for the background u place the image and the image will be shown in the background
      bg = PhotoImage(file="Images/back.png")
      canvas.create_image(5, 25, image=bg, anchor="nw")

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

    Thank you! you are helpful your name should be Pro coder

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

    thanks bro

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

    Muito bom...

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

    @Bro Code did you do something to prevent the 'file.write(filetext)' from returning an error "filetext is not defined' once you commented out the 'filetext = str(text.get(1.0,END)) ?

  • @Dani-zy6cf
    @Dani-zy6cf 2 года назад

    If you don't want to specify an specific file path for save the file, you can try this
    def saveFile():
    file = filedialog.asksaveasfile(defaultextension='.txt',filetypes=[("Text file",".txt"),("HTML file", ".html"),("All files", ".*")])
    if file is None:
    return
    filetext = str(text.get(1.0,END))
    #filetext = input("Enter some text I guess: ") //use this if you want to use console window
    file.write(filetext)
    file.close()

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

    can you please write me how to save a plot by using save window in tkinter?

  • @KevinIsAMilitaryGenius
    @KevinIsAMilitaryGenius 2 месяца назад

    mine keeps saying AttributeError: 'str' object has no attribute 'write' even though my code is exactly like this:file.write(filetext), and this is the line that it has problems with
    also when i tried to open the saved files on notpad it didnt recognize them and wanted me to create a new file, even though with the file we saved was asociated with the html property, i even made sure to see the properties segment to be sure it was html

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

    we meet again bro, great vid

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

    Can We Use Option Save As PDF To Save It As PDF??
    Waiting For Your Reply

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

      Instead waiting for reply try it yourself bro...

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

      Tried it, it saved. But it's not opening

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

    When i click save it wont work

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

    I'm developing a finance app to do some pretty calculations but I don't know how to save my results which is in a tkinter window as a pdf

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

    if i embed a matplotlib graph can i save it as a .png file using this method instead of the matplotlib provided saving method?

  • @48-_
    @48-_ Год назад +1

    nuclear launch codes O_O

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

    I want to Save file with all content of window(include Label, Button, Entry, Text) how to? please help

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

    Why does bro code have nuclear launch codes

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

    en mi caso es un PDF ya creado con todas sus estancias, como hago para que tome todos los parametros y luego guarde?

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

    hey, is there a way for it not to be able to have text?

  • @tamptus3479
    @tamptus3479 8 месяцев назад

    I miss a button to create a folder in the filesavedialog

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

    Is it possible to supply a default file name?

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

    meow meow meow~!

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

    How can i read my file and take it as a variable for using it inside the program?, if i use file as a global variable then pop ups again the asktoopenafile windows. i dont know if you can help me.

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

    why do u use camel case and no _?

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

    this is me helping you

  • @user-yd4zc6lt8z
    @user-yd4zc6lt8z 4 года назад

    Bro how do I save an image using tkinter? Please answer...I'm searching for it since 2 days

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

      Do you mean like a PhotoImage?

    • @user-yd4zc6lt8z
      @user-yd4zc6lt8z 4 года назад

      I made a Qrcode maker so I wanted to save image into PNG format just by pressing a button

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

    hey bro is there a way to safe file as written in tkinter example i have text boxes etc and i need them to safe however i tried this code but the txt file came back as empty is there a way to fix this?

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

    : )

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

    Thanks for the awesome video! Now how to use encode=('utf-8') within this code.

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

    wont show up for me

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

    i get this wierd thing. on filetext = str(text.get(1.0,END)) it says "function" object has no attribute "get"
    i have no idead what i did wrong i even copied ur line of text but still the same disgusting ass problem
    P.S i get this error when i close out of the save tab
    P.S again. I also get the same thing on text.write

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

    bro

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

    Helping you, help me, By commenting