python笔记本类如何在使用类时将数据放置在选项卡页上

2022-05-21 07:43:18 发布

您现在位置:Python中文网/ 问答频道 /正文

这里是新的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()

Tags: selfaddinitdefcallbackrootframelabelcommandtkmenuttkyearmenupumpmenu