Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So let's say I wanted to make a code editor and I want the contents in a text box to save by itself.
How would I do that, and where would I start?
Here is my thought:
I would create a function that saves the content and run it in a forever loop. But it won't work, so how would I do it.
Step one: make a function that saves the data:
def save():
data = the_text_widget.get("1.0", "end-1c")
with open("the_filename.txt", "w") as f:
f.write(data)
Next, write a function that calls this function over some interval, like every 10 seconds:
def autosave():
save()
the_text_widget.after(10000, autosave)
And finally, call this function once and it will run every 10 seconds:
autosave()
This isn't the only way, but it's arguably the simplest.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Im writting a script in Python that takes as an input a timestamp. For the first execution, it should be something as the now() function. However, for further executions, the input parameter should be the last execution time of the same script. This is being done to avoid getting duplicates results.
Can anyone give me a clue please?
As far as I know, there is no "last executed" attribute for files. Some operating systems have a "last accessed" attribute, but even if that's updated on execution, it would also be updated any time the file was read, which is probably not what you want.
If you need to be able to store information between runs, you'll need to save that data somewhere. You could write it to a file, save it to a database, or write it to a caching service, such as memcached.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am asking how to save a text file in python, that can contain a variable.
I didn't tried anything because I am a beginner.
Let's say you have a file called file and it is a notepad (text/txt) document. Your code would go like this:
text = "This can be anything"
with open("file.txt", "w") as myfile:
myfile.write(text)
The tutorial on reading and writing files should help if you don't understand this. The w means that you can write to the file.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I define a list that is empty at first and append to it but not have it clear when I restart my app? I am using python language
The list has the proper values in it when the app is first ran, it is only when I restart my app that the list clears because of the empty list variable over rides the list that was just created. Thanks in advance
A list doesn’t get saved when closing a python program. If you want this you should save the list in a specific file and load this file everytime your python program opens. One of the basics of python is that lists, dictionairies etc don’t get saved on change or exit.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to open an URL when someone click a button using PyQt4.
I used some suggested code already but none of them worked for me.
btn.clicked.connect(webbrowser.open('http://www.google.com'))
As Paul Ronney pointed out:
In your code you call the open method of object webbrowser immediately at the time this line of code is parsed. That is not what you want, you want to execute it later, when the button is clicked. For that you need to specify a method without executing it, i.e. without the ().
The method way:
def open_webbrowser():
webbrowser.open('http://www.google.com')
btn.clicked.connect(open_webbrowser)
Or with lambda expression:
btn.clicked.connect(lambda: webbrowser.open('http://www.google.com'))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I was wandering if anyone was able to help me properly add Tkinker into my existing script?. The Tkinker code works fine outside of the current script as does the script without the Tkinter code, but I am having trouble merging it together. been doing alot of searching and i cant seem to fine the answer i am looking for. Here is the link to my script:
https://github.com/Octane70/Code/blob/master/Garden/Garden_v0.3.py
Line 50 #GUI_window is the code i am trying to add.
Thanks
You need to call root.mainloop() exactly once. You need to convert your while True loop into a function, and at the end of the function you need to call itself again with after. This function should also update the GUI, though you could put that in a separate function if you wish.
You do not want to call your gui_display function more than once. As it stands now, you are creating six new widgets every second. Instead, you want to create them once and then update them every second.