-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use MemoryFS() to write/open files directly #563
Comments
You can't, but see the comments in #541 |
Thanks @lurch, I'll have to rethink this idea, while |
You might be interested to read about the |
I've been using various combinations of that but for some reason Windows really really does not want to let go of the files while the .py is running. Not sure what has made it that way, tried a few things and it's refusing to let go of the files until Python has stopped completely. I've got another idea in mind that might work just got to find the solution... |
Perhaps TK has a lock on the files, and so you somehow need to "unload" TK, before you try and close (and auto-delete) the TempFS? 🤷 |
Yea that's the case, as soon as Python has finished you can delete them. I've tried all sorts of variants of .close() and such but something's blocking it. As I say, if TK just accepted base64 strings I would be good to go, convert the PNG base64 string to an ICO base64 string, then pass that string in as the file, but no, that would be too easy 🤣 |
Do none of these work? https://www.google.com/search?q=python+unload+module |
Thanks for the suggestion, I worked through some of those then it dawned on me, it had worked until I introduced Short version, I had to create a 'death loop' that:
This all happens in a near instant so that's a bodge-tastic win, thanks for the suggestions @lurch it gave me enough to create the insanity required to do the job. Will be putting forward suggestions to TK about supporting both base64 and an internal png>ico converter for win users. |
Hi there,
I'm working on a small project for myself using customtkinter, one of the quirks of TK over PySimpleGUI is it's dislike of using PNG's as icons on Windows. To keep everything in one file I typically store a PNG(s) in the .py as a base64 strings, I can convert it to both a real PNG and ICO file using the below code:
At present I'm using
tempfile
to save the resulting two files which TK is happy to use and then delete them, at least that's the idea as trying toshutil.rmtree(tempdir)
on exit keeps giving file locks.Again due to TK weirdness you can't pump a base64 string into some of their variables such as
root.wm_iconbitmap
orroot.iconbitmap
they have to be files (they should fix this 😐). So I thought I would try to avoid real files with pyfilesystem's MemoryFS() but I'm struggling to make sense of it, it's not heavily used (but it should be) so examples are thin on the ground.Can someone help with how I write these two files in
app.save
to memory? I've got as far as;But I cannot figure out how to write/open files like a regular path, in this example above I need to write to
mem://ytico.ico
then call it back as a proper file later on, I guess for opening I can useicon = mem_fs.open('ytico.ico')
but again not sure.TL:DR;
How can I treat mem_fs as a regular path style equivalent to `c:\doc\myfile.txt'
The text was updated successfully, but these errors were encountered: