首页 > 解决方案 > python notebook类——使用类时如何在标签页上放置数据

问题描述

新的 python 用户在这里。我很抱歉无法弄清楚这一点。

我正在做一个具有菜单栏和笔记本选项卡的 GUI 应用程序,并希望使用类。我找到了一些执行此操作的代码并对其进行了修改。在我未经训练的眼睛看来,类实例化了自己,而不是在主代码中定义和单独的实例化和使用。

最后,我希望能够在每个选项卡式空间中放置图表和表格。但我无法弄清楚如何做到这一点。

    import tkinter as tk
from tkinter import ttk

import mdrparse_foidev_for_frn_only as maude
#from tkinter import  user

class Root(tk.Tk):
    """Container for all frames within the application"""

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

        #initialize menu
        self.config(menu=MenuBar(self))
        self.geometry("1500x500")
        self.appFrame = Application(self)
        self.appFrame.pack(side='top', fill='both', expand='True')

        self.status = StatusBar(self)
        self.status.pack(side='bottom', fill='x')

class MenuBar(tk.Menu):
    def __init__(self, parent):
        tk.Menu.__init__(self, parent)

        pumpmenu = tk.Menu(self, tearoff=False)
        self.add_cascade(label="Pump",underline=0, menu=pumpmenu)
        pumpmenu.add_command(label="Spectrum", command=self.callback)
        pumpmenu.add_separator()
        pumpmenu.add_command(label="Sappphire", underline=1, command=self.callback)

        yearmenu = tk.Menu(self, tearoff=False)
        self.add_cascade(label="Year", menu=yearmenu)
        yearmenu.add_command(label="2018...", command=self.callback)
        yearmenu.add_separator()
        yearmenu.add_command(label="2017", underline=1, command=self.callback)

        helpmenu = tk.Menu(self, tearoff=False)
        self.add_cascade(label="Help", menu=helpmenu)
        helpmenu.add_command(label="About...", command=self.callback)

# =============================================================================
#     def quit(self):
#         sys.exit(0)
# =============================================================================

    def callback(self):
        maude.parse_maude_file
        print ("Parsed the file")

class StatusBar(ttk.Frame):

    def __init__(self, master):
        ttk.Frame.__init__(self, master)
        self.label = ttk.Label(self, relief='sunken', anchor='w')
        self.label.pack(fill='x')

    def set(self, format, *args):
        self.label.config(text=format % args)
        self.label.update_idletasks()

    def clear(self):
        self.label.config(text="kooft")
        self.label.update_idletasks()


class Application(ttk.Notebook):
    def __init__(self, root):
        ttk.Notebook.__init__(self, root)

        tab1 = ttk.Frame(self,   width=200, height=200)
        tab2 = ttk.Frame(self)
        tab3 = ttk.Frame(self)

        self.add(tab1, text = "Table")
        self.add(tab2, text = "Graphs")
        self.add(tab3, text = "More")

#tab1.label("this is a test")

root = Root()

root.title("Maude Database Analysis Tool")



#root.iconbitmap('InfusionAnalyticsSmall.ico')
root.mainloop()

标签: pythonclasstkinter

解决方案


推荐阅读