На примере из поста здесь я создал приложение для переключения кадров.Когда я использовал StringVar в качестве переменной внутри страницы фрейма, которую я изменил, как показано ниже, пользовательский интерфейс не отображается, код работает в фоновом режиме
from tkinter import *
from tkinter import font as tkfont
import time
import threading
class RMS_APP(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
self.title("Restaurant Management System")
self.master = Frame(self)
self.master.grid(row=0,column=0,sticky='nwes')
#self.geometry("1600x800+0+0")
#self.master.value = StringVar()
self.master.grid_rowconfigure(0, weight=1)
self.master.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (LogIn,):#,Kitchen):
page_name = F.__name__
frame = F(parent=self.master, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("LogIn")
def show_frame(self, page_name,arg = None):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
if arg:
#frame.OnClick(arg)
#self.label1.grid_forget()
frame.label1['text'] = arg
pass
frame.tkraise()
class LogIn(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.controller = controller
self.localtime=time.asctime(time.localtime(time.time()))
label = Label(self, text="Restaurant Management System", font=controller.title_font)
label.grid(row=0,column=0,sticky='news',columnspan=3,padx = 500,pady=(150,10))
lblinfo = Label(self, font=controller.title_font,text=self.localtime,fg="black",anchor=W)
lblinfo.grid(row=1,column=0,columnspan=3,padx=500,pady=(0,10))
button1 = Button(self, text="Table",height = 10, width = 15,
command=lambda: controller.show_frame("Table"))
button2 = Button(self, text="Kitchen",height = 10, width = 15,
command=lambda: controller.show_frame("Kitchen"))
button3 = Button(self, text="Bill Table",height = 10, width = 15,
command=lambda: controller.show_frame("Kitchen"))
button1.grid(row=2,column=0,sticky='news',padx=(250,10),pady = (100,10))
button2.grid(row=2,column=1,sticky='news',padx=(0,10),pady = (100,10))
button3.grid(row=2,column=2,sticky='news',pady = (100,10))
if __name__ == "__main__":
app = RMS_APP()
app.mainloop()
Когда я отменяю комментарий в строке self.master.значение кода не запускается. комментируя его, я могу запустить код, и он отображает страницу входа. Есть ли еще что-то, что мне нужно проверить