Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter:从外部函数刷新帧/窗口_Python_Tkinter_Reload - Fatal编程技术网

Python Tkinter:从外部函数刷新帧/窗口

Python Tkinter:从外部函数刷新帧/窗口,python,tkinter,reload,Python,Tkinter,Reload,当updateCustomerList完成列表更新后,我想刷新MainPage,这样更新后的列表就会显示在MainPage小部件上 我尝试过使用tk.show_frame()等等。但是由于函数本身没有绑定到Tkinter主框架本身,或者甚至不是Tkinter对象,因此我不完全确定如何重新加载页面。有什么建议吗 下面的代码是我整个程序的一个片段: customerList = [] #list is updated at the updateCustomerList function; globa

updateCustomerList
完成列表更新后,我想刷新
MainPage
,这样更新后的列表就会显示在
MainPage
小部件上

我尝试过使用
tk.show_frame()
等等。但是由于函数本身没有绑定到Tkinter主框架本身,或者甚至不是Tkinter对象,因此我不完全确定如何重新加载页面。有什么建议吗

下面的代码是我整个程序的一个片段:

customerList = [] #list is updated at the updateCustomerList function; global variable

class POS(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 (ErrorPage, PaymentPage, MainPage): 
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column = 0, sticky = "nsew")

        #show frame here


class MainPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)
        """
        Tkinter frame that I would like to "refresh" and use the new updated list
        """
        frame5Button = ttk.Button(frame5, text = "Add Item", command = lambda: updateCustomerList(barCode, quantity))
        frame5Button.grid(row = 0, column = 5, padx = 90, pady = 10)
        #This button allows me to go into the updateCustomerList function

def updateCustomerList(barCode, quantity):
    #some code to update a list
    #when function finishes updating the list, I would like to go back to the MainPage Tk frame and reload all the widgets like labels and entry boxes using the updated customerList list

app = POS()
app.geometry("700x700") 
app.resizable(False, False)
app.after(100, MasterFilePopUp)
app.mainloop()

只需删除并重新创建
大型机的实例,将其作为
updateCustomerList
的最后一行:

container = 0 #global variable
在位置(tk.tk)内添加“全局容器”


只需删除并重新创建
大型机的实例,将其作为
updateCustomerList
的最后一行:

container = 0 #global variable
在位置(tk.tk)内添加“全局容器”


它不是在全局范围内创建的。它是在POS()类内部本地创建的,或者至少根据我的理解是这样的。尽管如此,我还是要试一试!那么,它是如何在
POS
中创建的呢?更新了上面发布的代码,以显示我是如何创建我的frames@Miggy更新了我的答案。我认为它应该有效,但我仍然需要解决一些问题。当我开始的时候会回来的。非常感谢。它不是在全局范围内创建的。它是在POS()类内部本地创建的,或者至少根据我的理解是这样的。尽管如此,我还是要试一试!那么,它是如何在
POS
中创建的呢?更新了上面发布的代码,以显示我是如何创建我的frames@Miggy更新了我的答案。我认为它应该有效,但我仍然需要解决一些问题。当我开始的时候会回来的。非常感谢。代码中的缩进已修复(请参见F…
循环的
)!感谢您让我知道您代码中的缩进已被修复(请参阅F…
循环的
)!谢谢你让我知道