У меня проблемы с обновлением текста метки с помощью вызова функции класса с помощью команды кнопки.Я разделил свой корневой кадр на пять подкадров.Однажды кнопка запускает командную функцию и запрашивает у пользователя входные файлы.Путь к входному файлу пользователя отображается в корневом кадре, а не в подкадре, из которого вызывается функция. введите описание изображения здесь
import tkinter as tk
from tkinter import *
from tkinter import filedialog as fd
from tkinter import ttk
LARGE_FONT = ('Verdana', 10)
def donothing():
print('Do Nothing')
class rootframe(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "ABC")
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 = {}
frame = StartPage(container, self)
self.frames[StartPage] = frame
frame.grid(row=0, column=0, sticky='nsew')
self.show_frame(StartPage)
for F in (StartPage, graph, piano):
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()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
sidebar = Frame(self, bg='whitesmoke', width=250, height=780,
borderwidth=2, relief='ridge')
statusbar = Frame(self, bg='whitesmoke', width=1280, height=30,
borderwidth=2, relief="ridge")
toolbar = Frame(self, bg='whitesmoke', width=1280, height=30,
borderwidth=2, relief='ridge')
helpbar = Frame(self, bg='whitesmoke', width=1280, height=150,
borderwidth=2, relief='ridge')
mainframe = Frame(self, bg='whitesmoke', width=1280, height=550,
borderwidth=2, relief="sunken")
sidebar.pack(side='left', anchor='sw')
statusbar.pack(side='bottom', anchor='center')
toolbar.pack(fill=X, side='top', anchor='center')
helpbar.pack(side='bottom', anchor='center')
mainframe.pack(side='top', anchor='center')
label = tk.Label(toolbar, text='Start Page', font=LARGE_FONT)
label.pack(side='left', anchor='sw', expand=True)
button2 = ttk.Button(toolbar, text='File Merge Tool',
command=lambda: controller.show_frame(piano))
button2.pack(side='left', expand=True)
button3 = ttk.Button(toolbar, text='Graph Page',
command=lambda: controller.show_frame(graph))
button3.pack(side='left', expand=True)
class piano(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = parent
filename = " "
sidebar = Frame(self, bg='whitesmoke', width=250, height=780, borderwidth=2,
relief='ridge')
statusbar = Frame(self, bg='whitesmoke', width=1280, height=30,
borderwidth=2, relief="ridge")
toolbar = Frame(self, bg='whitesmoke', width=1280, height=30, borderwidth=2,
relief='ridge')
helpbar = Frame(self, bg='whitesmoke', width=1280, height=150,
borderwidth=2, relief='ridge')
mainframe = Frame(self, bg='whitesmoke', width=1280, height=550,
borderwidth=2, relief="sunken")
sidebar.pack(side='left', anchor='sw')
statusbar.pack(side='bottom', anchor='center')
toolbar.pack(fill=X, side='top', anchor='center')
helpbar.pack(side='bottom', anchor='center')
mainframe.pack(side='top', anchor='center')
button2 = ttk.Button(toolbar, text='HOME',
command=lambda: controller.show_frame(StartPage))
button2.pack(side='right', anchor='nw', expand=True)
label = tk.Label(mainframe, text='File Merge', font=36)
label.place(x=510, y=10)
label1 = tk.Label(mainframe, text='file1', font=LARGE_FONT)
label1.place(x=0, y=60)
inp1 = ttk.Button(mainframe, text='Browse',
command=lambda: piano.readfile())
inp1.place(x=800, y=60)
pathlabel = Label(mainframe, background='white', width=80, relief='sunken',
borderwidth=4)
pathlabel.place(x=220, y=60)
pathlabel.config(text=filename)
label2 = tk.Label(mainframe, text='file2', font=LARGE_FONT)
label2.place(x=0, y=80)
inp2 = ttk.Button(mainframe, text='Browse',
command=lambda: piano.readfile())
inp2.place(x=800, y=80)
pathlabel1 = Label(mainframe, background='white', width=80, relief='sunken',
borderwidth=4)
pathlabel1.place(x=220, y=80)
pathlabel1.config(text=filename)
def readfile():
filename = fd.askopenfilenames(filetypes=[("TXT Files", "*.txt")])
pathlabel = Label(background='white', width=80, relief='sunken',
borderwidth=4)
pathlabel.place(x=220, y=60)
pathlabel.config(text=filename)
class graph(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = ttk.Label(self, text='Graph', font=LARGE_FONT)
label.pack(pady=10, padx=10)
button1 = ttk.Button(self, text='Back to Home',
command=lambda: controller.show_frame(StartPage))
button1.pack()
app = rootframe()
app.mainloop()