猿问

提升包含小部件的TK框架

我试图重现经典的“切换帧”示例。我正在尝试包括几个tkk小部件,并已使用.grid()而不是.pack()。切换帧效果很好,但是,我raising在tkk小部件上遇到了麻烦。


import Tkinter as tk

import ttk

from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2TkAgg)

import matplotlib.pyplot as plt

import numpy as np




class SampleApp(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)


        container = tk.Frame(self)

        container.grid()

        container.grid_rowconfigure(0, weight=1)

        container.grid_columnconfigure(0, weight=1)


        self.frames = {}

        for F in (StartPage, PageOne):

            page_name = F.__name__

            frame = F(parent=container, controller=self)

            self.frames[page_name] = frame

            frame.grid(row=0, column=0, sticky="nsew")


        self.show_frame("StartPage")


    def show_frame(self, page_name):

        '''Show a frame for the given page name'''

        frame = self.frames[page_name]

        frame.tkraise()



class StartPage(tk.Frame):

    def __init__(self, parent, controller):

        tk.Frame.__init__(self, parent)

        self.controller = controller

        self.window = parent

        label = tk.Label(self, text="This is the start page")

        label.grid(pady=10)


        button1 = tk.Button(self, text="Go to Page One",

                            command=lambda: controller.show_frame("PageOne"))

        button1.grid()

        self.create_widgets()

如果运行此命令,您会发现我可以完美地从StartPage和PageOne更新Pages,但是绘图不会从Sin变为Cosin!为什么?



Qyouu
浏览 183回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答