2016-07-28 9 views
-2

Ich wollte einen Code erstellen, mit dem ich ein Verzeichnisfenster öffnen und eine CSV-Datei aus einem Ordner auswählen konnte. Ich wollte 4 Knöpfe machen, die das tun würden, und dann eine Taste, die, wenn sie gedrückt wurde, einen Code ausführen und eine neue Datei schreiben würde.Wie kann ich eine Schaltfläche erstellen, die auf eine Datei in tkinter zugreift?

Ich habe es mehrere Möglichkeiten ausprobiert, aber bisher habe ich nicht viel dies ist mein Code:

from tkinter import* 



#how to organize layout# 
root = Tk() #CONSTRUCTOR(think blank window in your head) 

topFrame = Frame(root) #this is pretty much saying, 
        # "i'm gonna make an invisible container and is gonna go into themain window, 
        # root". 

topFrame.pack()  #everytime there is something to display we have to pack it in. 

#Do the exact same thing for the bottom frame 

bottomFrame = Frame(root) 
bottomFrame.pack(side=BOTTOM) 

#let's through some widgets in here 

button1 = Button(topFrame,text="Button1",fg="yellow") 
button2 = Button(topFrame,text="Button2",fg="blue") 
button3 = Button(topFrame,text="Button3",fg="red") 
button4 = Button(topFrame,text="Button4",fg="white") 
button5 = Button(bottomFrame,text="Button5",fg="black") 

button1.pack(side=LEFT) 
button2.pack(side=LEFT) 
button3.pack(side=LEFT) 
button4.pack(side=LEFT) 
button5.pack(side=BOTTOM) 
+0

'tkinter.filedialog.askdirectory' ist wahrscheinlich, was Sie suchen –

Antwort

1

Etwas in dieser Richtung:

from Tkinter import * 
def getFile(): 
    # Get File Code 

b = Button(text="click me", command=getFile) 
b.pack() 

von command=getFile Verwendung Tk zu nennen weiß die getFile Methode, wenn auf die Schaltfläche geklickt wird.

Viel Glück!