繁体   English   中英

如何使用python中的文件路径?

[英]How to use file paths in python?

我这里有一个代码,我想发送给我的朋友。 问题是它指定了路径。 我该怎么做才能更正它自己文件夹的路径?

代码:

# 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() 

路径为:C:\Users\regok\Desktop\VFIDG\arrow.png。 我想将其设置为当前文件夹 \ arrow.png

您可以只使用input()filedialog 正如 Cool Cloud 评论的那样,另一种选择是将路径设置为相对于文件本身。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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