ich hab ein Fenster mit Entry, Button und Textfeld. Wenn ich den Loadbutton drücke und eine Datei anwähle, soll er mir den Dateipfad ins Entry schreiben. Ich weiß, dass man das mit Klassen hinkriegt, aber ich wollt darauf eigentlich verzichten. Nebenbei weiß ich auch nicht, warum das Dateifenster schon beim Start kommt und nicht erst beim Button drücken.
(filepath enthält nicht nur den Pfad, aber das mach ich später, mir gehts erstmal um die Variablenübergabe).
Code: Alles auswählen
from Tkinter import *
from tkFileDialog import askopenfile
wwidth=300
wheight=300
def load():
file=askopenfile(mode='r')
filepath = str(file)
return filepath
app = Tk()
topframe = Frame(width=wwidth, height=wheight/10)
topframe.pack()
botframe = Frame(width=wwidth, height=wheight/10*9)
botframe.pack()
btnLoad = Button(app, text="Load nuke file!", command=load())
btnLoad.pack()
btnLoad.place(x=375, y=2)
namefield = Entry(app, text="test", width=60)
namefield.insert(END,"hi") ### anstelle von "hi" soll hier der Dateipfad stehen
namefield.pack()
namefield.place(x=5, y=2)
app.columnconfigure(0, weight=5)
app.columnconfigure(1, weight=1)
infofield = Text(botframe)
infofield.pack()
app.protocol("WM_DELETE_WINDOW", app.quit)
app.mainloop()
app.destroy()