ich bin Anfänger im Bereich tkinter. Aktuell versuche ich den Pfad abzudrucken, welche von einem filedialog zurückgegeben wird.
Code: Alles auswählen
import tkinter as tk
from tkinter import ttk
from pathlib import Path
from tkinter.filedialog import askopenfilename
class MainWindow(tk.Tk):
# Benutzeroberfläche
def __init__(self):
tk.Tk.__init__(self)
self.title("Beispiel")
self.geometry('600x600')
self.file_path = None
tabControl = ttk.Notebook(self)
tab1 = ttk.Frame(tabControl)
tabControl.add(tab1, text='Reiter 1')
tabControl.pack(expand=1, fill='both')
# Buttons für Tab1
tk.Button(tab1, text="Öffnen", command=self.select_button1).grid(
row=0, column=0, padx=15, pady=15
)
tk.Label(tab1, textvariable=self.file_path).grid(row=1, column=1, padx=15, pady=15)
def select_button1(self):
filename = askopenfilename(
initialdir=Path.home(),
title="Open file",
filetypes=(("txt Dateien", "*.txt"),),
)
if filename:
self.file_path = Path(filename)
def main():
MainWindow().mainloop()
if __name__ == "__main__":
main()
Vielen Dank für eure Hilfe!