i'm trying to make (text1) the Entry to get the file path that i open to show up what i mean whin i open a file it show me the file path on the entry(textbox) ps: sorry for the bad example and English
''''python
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror
from tkinter import ttk
here is my class for the fream
class SchoolProjict(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side = "top", fill = "both", expand = True)
container.grid_rowconfigure(0, weight = 1)
container.grid_columnconfigure(0, weight = 1)
self.frames = {}
for F in (StartPage, PageOne, SetingPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row = 0, column = 0, sticky = "nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
this on to test printing from entry
def printingstuff(var1):
print (var1)
this to open a file i want it to chang the entry to show the file path
def load_file():
fname = askopenfilename(filetypes=(("Excel file", "*.xls"),
("HTML files", "*.html;*.htm"),
("All files", "*.*") ))
if fname:
try:
print(fname)
return
except: # <- naked except is a bad idea
showerror("Open Source File", "Failed to read file\n'%s'" % fname)
return
here are the frames for the program
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
lablel = tk.Label(self, text = "Start Page")
lablel.pack(pady = 10, padx = 10)
button1 = tk.Button(self, text = "Main Menu", command = lambda: controller.show_frame(PageOne))
button1.pack()
button2 = tk.Button(self, text = "Siting", command = lambda: controller.show_frame(SetingPage))
button2.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
lablel = tk.Label(self, text = "Main Menu")
lablel.pack(pady = 10, padx = 10)
button1 = tk.Button(self, text = "Start Page", command = lambda: controller.show_frame(StartPage))
button1.pack()
button2 = tk.Button(self, text = "Siting", command = lambda: controller.show_frame(SetingPage))
button2.pack()
class SetingPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
lablel = tk.Label(self, text = "Siting Page")
lablel.pack(pady = 10, padx = 10)
text1 = ttk.Entry(self)
text1.pack()
text1.focus()
button1 = tk.Button(self, text = "Print from Entry", command = lambda: printingstuff(text1.get()))
button1.pack()
button2 = tk.Button(self, text="open File", command= load_file, width=10)
button2.pack()
button3 = tk.Button(self, text = "Main Menu", command = lambda: controller.show_frame(PageOne))
button3.pack()
button4 = tk.Button(self, text = "Start Page", command = lambda: controller.show_frame(StartPage))
button4.pack()
the main loop thing
app = SchoolProjict()
app.mainloop()
'''' i am sorry if it dose not make any sense