Python Forum
[Tkinter] Default Paths
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Default Paths
#1
Ok, guys. Major stupidity on my part. I have mad an exe file and post it on sourceforge.net, but the program will not work.
This, because the main file and secondary ones required extensions (images, audio, etc), which are indicate by window path (C:/Users/Desktop/"My name"/Project/image.png)

I totally forgot the part, when it goes to another computer it will never work, because the computer path will not be the same one as mine. Anyway to fix this, to a default path or something, so all the files call be called and work?

Any replies much appreciated. Again major error and stupidity of my part, i totally forgot about that. Doh
Reply
#2
import os
from pathlib import Path
d = Path(__file__).parent
sound = os.path.join(d, 'Folder', 'Keep adding folders/files till you get to the file')
Reply
#3
I think you want package data. See also the module importlib.resources for accessing package data from the code (starting with 3.7, before that it was pkg_resources)
Reply
#4
But, for example, if i change it only C:\Project will not work?
Reply
#5
Linux users do not have "C:"

And I'm also pretty sure someone on Linux has regular slashes - /
Reply
#6
(Apr-22-2019, 07:37 PM)SheeppOSU Wrote: Linux users do not have "C:"

And I'm also pretty sure someone on Linux has regular slashes - /

Ok, right now, just for windows, then for others. i would love to get this to work. and see what portuguese people think about it and improve it based on the feedback i hope to receive
Reply
#7
(Apr-22-2019, 07:12 PM)francisco_neves2020 Wrote: But, for example, if i change it only C:\Project will not work?
I guess that is fine. If I'm correct, you mean to put all the pictures and stuff there, if so, that will work.
Reply
#8
(Apr-22-2019, 07:05 PM)SheeppOSU Wrote:
import os
from pathlib import Path
d = Path(__file__).parent
sound = os.path.join(d, 'Folder', 'Keep adding folders/files till you get to the file')

Man i didn't get the part until i get the file. There is one major pyw file, within this major pyw file there is from subprocess call others pyw. This major file has attached to it one png, then there are 2 or 3 secondary with png attached also and one with 10 png images(slideshow). The one with that code will be the major one, where i will indicate all the other files, except itself)?
Reply
#9
I don't exactly get the question, but if you're asking but with a lot of pictures you could just do this -
import os
from pathlib import Path
d = Path(__file__).parent
x = 0
picList = ['file.png', 'file.png', 'file.png', 'file.png']
for i in picList:
    picList[x] = os.path.join(d, 'Pic Folder', i)
    x += 1
Hope i didn't make any mistakes on there

Oh! I just remembered - If they are in the same directory as the file you just have to put the name of the picture
Reply
#10
(Apr-22-2019, 08:04 PM)SheeppOSU Wrote: I don't exactly get the question, but if you're asking but with a lot of pictures you could just do this -
import os
from pathlib import Path
d = Path(__file__).parent
x = 0
picList = ['file.png', 'file.png', 'file.png', 'file.png']
for i in picList:
    picList[x] = os.path.join(d, 'Pic Folder', i)
    x += 1
Hope i didn't make any mistakes on there

Oh! I just remembered - If they are in the same directory as the file you just have to put the name of the picture

Based on this picture you may get an ideia

[Image: FDJmzXd]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter and image paths menator01 2 3,512 Apr-14-2020, 08:46 PM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020