1

I have a code here, that I want to send to my friend. The problem is that it has a path specified. How would I make it so it would correct the path to its own folder?

Code:

# importing only those functions 
# which are needed 
from tkinter import * 
from tkinter.ttk import *
  
# creating tkinter window 
root = Tk() 
  
root.title("Vidman-féle Instant Depresszió Generátor")

root.geometry('600x200')

root.configure(background='white')
  
lbl = Label(root, text="0").pack(side = TOP) 

txt = Entry(root,width=10).pack(side =TOP) 

def clicked():

    res = int(float(Entry.get())) * int(60000)
    lbl.configure(text= res)


# Creating a photoimage object to use image 
photo = PhotoImage(file = r"C:\\Users\\regok\\Desktop\\VFIDG\\arrow.png") 
  
# here, image option is used to 
# set image on button 
Button(root, text = 'Click Me !', image = photo, command=clicked).pack(side = BOTTOM) 
  
mainloop() 

The path is: C:\Users\regok\Desktop\VFIDG\arrow.png. I would like to set it as currentfolder\arrow.png

  • Use relative pathing, `photo = PhotoImage(file ="arrow.png")` – Delrius Euphoria Feb 16 '21 at 19:01
  • You can get the folder of the current script via `os.path.dirname(__file__)`. – martineau Feb 16 '21 at 19:10
  • When you say **currentfolder** do you mean the actual _current working directory_ or the folder that the script is in? Those are two different things, and most people asking this sort of question usually mean the latter. – Bryan Oakley Feb 16 '21 at 19:14

1 Answers1

0

You could just use input() or a filedialog. Another option would be setting the path to be relative to the file itself as Cool Cloud commented.

kippel
  • 131
  • 4