Programımın kullanıcı tarafından girilen bir dosya yolunu açmaya çalışıyorum. Bu girişlisteme kaydedildi, daha sonra os.system
işlevini kullanarak çağırıyorum. Kaydedilmiş dosya yolunu açmak yerine, kaşif açılır ve Beni Belgelerim'e götürür. 1. Neden bu oluyor?2. Gezginin kayıtlı kullanıcı verilerine açık olması için bunu nasıl değiştirebilirim?Python: Program explorer'da yanlış dosya yolunu açar?
import Tkinter as tk
import pickle
import os
data = []
class MyPath(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.parent = parent
self.pack()
MyPath.make_widgets(self)
def make_widgets(self):
self.parent.title("MyPath")
#self.textbox = Text(root)
#self.textbox.pack()
# create a prompt, an input box, an output label,
# and a button to do the computation
self.prompt = tk.Label(self, text="Enter your Filepath:", anchor="w")
self.textbox = tk.Text(self)
self.entry = tk.Entry(self)
self.open = tk.Button(self, text="Open", command = self.open)
self.view = tk.Button(self, text="View", command = self.view)
self.submit = tk.Button(self, text="Save", command = self.save)
self.output = tk.Label(self, text="")
self.clear_button = tk.Button(self, text="Clear text", command=self.clear_text)
# lay the widgets out on the screen.
self.prompt.pack(side="top", fill="x")
self.entry.pack(side="top", fill="x", padx=20)
self.output.pack(side="top", fill="x", expand=True)
self.textbox.pack(side="top", fill="x")
self.view.pack(side="bottom")
self.submit.pack(side="bottom")
self.clear_button.pack(side="bottom")
self.open.pack(side="top")
def clear_text(self):
self.entry.delete(0, 'end')
self.textbox.delete(1.0, 'end')
def save(self):
# get the value from the input widget
try:
a = self.entry.get()
result = data.append(self.entry.get())
except ValueError:
result = "Please enter filepaths only"
#saves list to pickle file
#pickle.dump(data, open("save.p", "wb"))
# set the output widget to have our result
self.output.configure(text=result)
print (data)
def view(self):
pickle.load(open("save.p", "rb"))
self.textbox.insert("1.0", str(pickle.load(open("save.p", "rb"))))
print pickle.load(open("save.p", "rb"))
def open(self):
#src = "/Users/matt/Documents/Python/MyApp.py"
dst = data
#path = pickle.load(open("save.p", "rb"))
os.system('Explorer "data[0]"')
if __name__ == "__main__":
root = tk.Tk()
MyPath(root).pack(fill="both", expand=True)
root.mainloop()
Herhangi bir yardım çok takdir edilmektedir! Sonunda dizenizle Nedeni
arayarak, örnek yöntemler , class.method (self) 'yerine self.method() işlevini kullanın. İkinci form, statik yöntemler için yaygın olarak kullanılır. –