Python GUI save a file (filedialog) 💾

  Рет қаралды 42,922

Bro Code

Bro Code

Күн бұрын

Python GUI filedialog tkinter save a file tutorial for beginners
#Python #GUI #save #filedialog #tkinter #file #tutorial #beginners
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()

Пікірлер: 70
@BroCodez
@BroCodez 4 жыл бұрын
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!
@Sirbozo
@Sirbozo 3 ай бұрын
why not any one see and comment the nuclear launch codes???? XD
@vinayaknayak5480
@vinayaknayak5480 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")
@Dangerous_Milk
@Dangerous_Milk 2 жыл бұрын
Very awesome tutorial, thank you! :3 but why do you have a folder named nuclear launch co...
@notacupofmilk2021
@notacupofmilk2021 Жыл бұрын
Why does bro code have nuclear launch codes
@48-_
@48-_ Жыл бұрын
nuclear launch codes O_O
@playerwin20
@playerwin20 3 жыл бұрын
When i click save it wont work
@johnsonmcdonald292
@johnsonmcdonald292 3 жыл бұрын
Appreciate this. Thanks a lot!
@KevinIsAMilitaryGenius
@KevinIsAMilitaryGenius Ай бұрын
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
@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
@sanketgunjal6079
@sanketgunjal6079 3 жыл бұрын
Thanks alot for this simple and effective explaination
@BroCodez
@BroCodez 3 жыл бұрын
thanks for watching Sanket!
@MsDonquihote
@MsDonquihote Жыл бұрын
I want to Save file with all content of window(include Label, Button, Entry, Text) how to? please help
@spike666spike666
@spike666spike666 10 ай бұрын
Thanks for the awesome video! Now how to use encode=('utf-8') within this code.
@alejandropoirier6493
@alejandropoirier6493 Жыл бұрын
I'm developing a tool in my job and this tutorial helped me a LOOOOT. Thank you!
@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
@joshtornquist1937
@joshtornquist1937 4 жыл бұрын
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 жыл бұрын
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)
@sidtheepic1103
@sidtheepic1103 5 ай бұрын
Nah bro is a national threat, packing nuclear codes like that😂😂
@tamptus3479
@tamptus3479 7 ай бұрын
I miss a button to create a folder in the filesavedialog
@christianihechi
@christianihechi 4 ай бұрын
Thank you once again Bro!
@peterschrimpel9375
@peterschrimpel9375 2 жыл бұрын
nice, 3 steps done
@kjk539876
@kjk539876 3 жыл бұрын
thank you bro
@lordmanuels8677
@lordmanuels8677 4 ай бұрын
This video is great!!
@ghaithdev
@ghaithdev Жыл бұрын
Is it possible to supply a default file name?
@ОГУРЕЦ-ч2д
@ОГУРЕЦ-ч2д 4 жыл бұрын
thank you for this video ,(there is little information about gui in Russia)
@fentonmsu
@fentonmsu 3 жыл бұрын
Да я знаю, но есть несколько капелек.
@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.
@Dani-zy6cf
@Dani-zy6cf Жыл бұрын
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()
@rahitechworld589
@rahitechworld589 3 жыл бұрын
Nice video
@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.
@Yashhhmek28
@Yashhhmek28 3 ай бұрын
Such a nice tutorial ❤
@nadaviloz11
@nadaviloz11 3 ай бұрын
thank you very much
@telckiewell
@telckiewell 2 жыл бұрын
why do u use camel case and no _?
@arjunbhardwaj7526
@arjunbhardwaj7526 2 жыл бұрын
this is me helping you
@ahmadmureed4739
@ahmadmureed4739 2 жыл бұрын
can you please write me how to save a plot by using save window in tkinter?
@anokhautomation4453
@anokhautomation4453 3 жыл бұрын
Nice tutorial 👍👍very very informative and useful. Thanks for your kindful. 🙏
@cristiucvladimir7909
@cristiucvladimir7909 4 ай бұрын
thanks bro
@flxshaep632
@flxshaep632 2 жыл бұрын
wont show up for me
@gustavoaponte1814
@gustavoaponte1814 Жыл бұрын
meow meow meow~!
@Data_Falcon
@Data_Falcon 5 ай бұрын
bro
@nikhilrao6701
@nikhilrao6701 3 жыл бұрын
Already liked and subscribed, Commenting now to keep this channel running. Lets beat the algorithm Broooooooooooooooooooooo
@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?
@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)) ?
@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?
@seifelshlkany5032
@seifelshlkany5032 2 жыл бұрын
Thank you! you are helpful your name should be Pro coder
@lockedgaming6081
@lockedgaming6081 2 жыл бұрын
hey, is there a way for it not to be able to have text?
@kevinrussell6530
@kevinrussell6530 Жыл бұрын
Great video......as usual!
@alexdynamo1385
@alexdynamo1385 Жыл бұрын
It very useful for me
@jhassee
@jhassee Жыл бұрын
Helping you, help me, By commenting
@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?
@johnkerch9135
@johnkerch9135 2 жыл бұрын
same man lmao. any fix yet?
@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
@philtoa334
@philtoa334 3 жыл бұрын
: )
@beingzero7541
@beingzero7541 2 жыл бұрын
Wow!!!!
@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
@estudosacademicos5237
@estudosacademicos5237 3 жыл бұрын
Muito bom...
@deepdaddy1208
@deepdaddy1208 4 жыл бұрын
we meet again bro, great vid
@BroCodez
@BroCodez 4 жыл бұрын
thank you
Learn Python tkinter GUI menubars easy 🧾
10:49
Bro Code
Рет қаралды 21 М.
Open Files Dialog Box - Python Tkinter GUI Tutorial #15
12:34
Codemy.com
Рет қаралды 192 М.
From Small To Giant Pop Corn #katebrush #funny #shorts
00:17
Kate Brush
Рет қаралды 71 МЛН
An Unknown Ending💪
00:49
ISSEI / いっせい
Рет қаралды 57 МЛН
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 13 МЛН
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 8 МЛН
Saving and loading in pygame with json
25:23
Clear Code
Рет қаралды 29 М.
Read And Write To Text Files - Python Tkinter GUI Tutorial #100
14:33
Use a Drag & Drop Editor to Make Tkinter Python GUI Applications!
11:16
Python GUI open a file (filedialog) 📁
7:38
Bro Code
Рет қаралды 98 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,5 МЛН
shutil: The Ultimate Python File Management Toolkit
14:32
NeuralNine
Рет қаралды 11 М.
Intermediate Python Tutorial - Creating a Text Editor App
24:00
Tech With Tim
Рет қаралды 37 М.
Learn Python tkinter GUI frames easy ⚰️
6:50
Bro Code
Рет қаралды 13 М.
Scripting with Python - Modify a TXT file
19:00
My IT Workshop
Рет қаралды 50 М.
From Small To Giant Pop Corn #katebrush #funny #shorts
00:17
Kate Brush
Рет қаралды 71 МЛН