如何在应用程序中刷新tkinter窗口

时间:2016-03-31 13:35:52

标签: python tkinter window refresh frame

之前已经介绍了主题,但由于某种原因,该解决方案在我的应用中无效。

import sys
import tkinter as tk
import tkinter.messagebox


class SampleApp(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)

    menubar = tk.Menu(self)
    file_menu = tk.Menu(menubar)
    file_menu.add_command(label='Quit', command=sys.exit)
    menubar.add_cascade(label='File', menu=file_menu)
    self.config(menu=menubar)

    self.frames = {}
    for F in (
              , choiceMenu
              , newEntry
              ):
        frame = F(container, self)
        self.frames[F] = frame
        frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(logging)

   def show_frame(self, c):
       frame = self.frames[c]
       frame.tkraise()


class newEntry(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        #adding some entries and labels here


    def newProd(self):
    #this function takes the entry values and uses them to amend the database (sqlite db);
    self.controller.show_frame(choiceMenu)


 class ViewOrd(tk.Frame):

def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.controller = controller
    label1=tk.Label(self,text='ID').grid(row=1,column=0)


    button = tk.Button(self, text="Back to menu",command=lambda: controller.show_frame(choiceMenu)).grid(column=2)

当我向数据库(新行)中的表添加新订单时,我将看不到ViewOrd框架中的任何更改(显示所有已下订单),直到我重新运行整个应用程序。如何刷新ViewOrd帧并提取修改后的表格版本以便向用户显示?调用刷新功能的方式并不重要(ViewOrd框架中的按钮或自动刷新功能)。

0 个答案:

没有答案