python - 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()
解决方案
推荐阅读
- r - 在 R 中使用 try 连接 xts 对象失败
- c# - 如何遍历 DataTable SELECT 查询以获取具有相同linked_comp_id 的所有记录
- javascript - 加载延迟加载内容所需的 JS 脚本
- sql - 如何比较 SQL 中的两个模式数据快照?
- database - 如何同步多个 MongoDB 实例?
- ios - iOS - 应用程序终止时的后台服务
- amazon-web-services - 使用 Cloudfront 和 AWS Lambda 对 S3 托管网站进行身份验证时出现 503 错误
- json - "status_code": 422, "error_code": "REQUEST_PARAM_PARSE", "detail": "'data' 参数必须是一个列表"
- python - python中的原子`ln -sf`(符号链接覆盖现有文件)
- python - 两个输入图像必须在函数 'cv::StereoBMImpl::compute' 中有 CV_8UC1