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()
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
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.
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 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!
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)
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")
@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)) ?
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()
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
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.
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?
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
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()
Thank you :)
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
Is there a way?
only a real Bro leaves the code in the comments and description, thanks!
I'm developing a tool in my job and this tutorial helped me a LOOOOT. Thank you!
Already liked and subscribed, Commenting now to keep this channel running. Lets beat the algorithm Broooooooooooooooooooooo
Thanks alot for this simple and effective explaination
thanks for watching Sanket!
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.
Such a nice tutorial ❤
Appreciate this. Thanks a lot!
Nice video
This video is great!!
Great video......as usual!
nice, 3 steps done
Thank you once again Bro!
Very awesome tutorial, thank you! :3
but why do you have a folder named nuclear launch co...
why not any one see and comment the nuclear launch codes???? XD
It very useful for me
thank you very much
thank you for this video ,(there is little information about gui in Russia)
Да я знаю, но есть несколько капелек.
Nah bro is a national threat, packing nuclear codes like that😂😂
Wow!!!!
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.
sorry I'm not sure I understand. Do you mean such as having a default file location set up to read/write files to?
@@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!
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)
thank you bro
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
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")
Thank you! you are helpful your name should be Pro coder
thanks bro
Muito bom...
@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)) ?
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()
can you please write me how to save a plot by using save window in tkinter?
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
we meet again bro, great vid
thank you
Can We Use Option Save As PDF To Save It As PDF??
Waiting For Your Reply
Instead waiting for reply try it yourself bro...
Tried it, it saved. But it's not opening
When i click save it wont work
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
if i embed a matplotlib graph can i save it as a .png file using this method instead of the matplotlib provided saving method?
nuclear launch codes O_O
I want to Save file with all content of window(include Label, Button, Entry, Text) how to? please help
Why does bro code have nuclear launch codes
en mi caso es un PDF ya creado con todas sus estancias, como hago para que tome todos los parametros y luego guarde?
hey, is there a way for it not to be able to have text?
I miss a button to create a folder in the filesavedialog
Is it possible to supply a default file name?
meow meow meow~!
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.
why do u use camel case and no _?
this is me helping you
Bro how do I save an image using tkinter? Please answer...I'm searching for it since 2 days
Do you mean like a PhotoImage?
I made a Qrcode maker so I wanted to save image into PNG format just by pressing a button
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?
same man lmao. any fix yet?
: )
Thanks for the awesome video! Now how to use encode=('utf-8') within this code.
wont show up for me
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
bro
Helping you, help me, By commenting