简体   繁体   中英

How to use file paths in python?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM