我应该使用什么策略来让 GUI 选择一个数据集(API Get)将其存储在框架中,并允许编辑数据帧以更新 API(API 补丁)?我最初创建的 GUI 和功能是分开的。一切正常,但如果有人编辑表中的数据框,我无法捕获数据框的更改。
一位同事建议我需要创建一个类来捕获数据帧的状态。
为 GUI 创建一个类。
a.创建画布。
b.在画布内为 pandastable Table 创建一个框架。
GUI 有标签和按钮来过滤 API Get 请求。
a.项目和名称过滤器的标签/文本框。
b.按钮选择要运行的 API Get 请求。
我开始感到困惑了。 选择数据集的按钮应该是函数命令,还是类方法?
import tkinter as tk
from tkinter import *
import pandas as pd
from pandastable import Table, TableModel, config
from drofus import Projects, Items #, RoomTemplates, Items, Rooms
WINDOW_WIDTH = 940
WINDOW_HEIGHT = 500
HEADER_HEIGHT = round(WINDOW_HEIGHT/15, 0)
HEADER_FONT = int(round(WINDOW_HEIGHT/20, 0))
BUTTON_WIDTH = 20
PROJECT = 'Projects'
ITEM = "Items"
def get_project(filter: str) -> pd.DataFrame:
module = Projects()
# dRofus API request
projects = module.filter(filter_api=filter)
with pd.option_context("future.no_silent_downcasting", True):
projects.infer_objects(copy=False).drop(projects.iloc[:, 10:19], inplace=True, axis=1)
projects_revised = projects.rename(columns={'Template Name':'Project'})
return projects_revised
def get_item():
pass
class Drofus(Frame):
"""Basic test frame for the table"""
def __init__(self, parent=None):
self.parent = parent
Frame.__init__(self)
self.main = self.master
self.main.geometry(f"{WINDOW_WIDTH}x{WINDOW_HEIGHT}")
self.main.title('Design Standards Database')
self.canvas = Canvas(self.main,
width=WINDOW_WIDTH,
height=WINDOW_HEIGHT,
background='white',
borderwidth=0,
highlightthickness=0)
header_id = self.canvas.create_text(WINDOW_WIDTH / 2, HEADER_HEIGHT, text="Welcome",
font=("Arial", HEADER_FONT, "normal"), fill="dimgrey", anchor='s')
self.canvas.grid(row=0, column=0, columnspan=4)
table_frame = Frame(self.main, highlightthickness=5, highlightcolor="orange")
table_frame.grid(row=0, column=0, padx=40, pady=40)
df = get_project(filter="None")
self.table = pt = Table(table_frame,
dataframe=df,
showtoolbar=False,
showstatusbar=True)
pt.show()
proj_filter_label = Label(table_frame, text="Project filter")
proj_filter_label.grid(row=4, column=1, sticky="e")
name_filter_label = Label(table_frame, text="Name filter")
name_filter_label.grid(row=5, column=1, sticky="e")
proj_filter_textbox = Entry(table_frame)
proj_filter_textbox.grid(row=4, column=2, sticky="w")
name_filter_textbox = Entry(table_frame)
name_filter_textbox.grid(row=5, column=2, sticky="w")
module_options = [PROJECT, ITEM]
module_variable = StringVar(value=module_options[0])
module_variable.set("dRofus Module")
module_dropdown = OptionMenu(table_frame, module_variable, *module_options, command=select_dataset)
module_dropdown.config(width=BUTTON_WIDTH)
module_dropdown.grid(row=5, column=3, sticky="w")
return
def select_dataset(event):
selected = module_variable.get()
if select == PROJECT:
if proj_filter_textbox.get():
module_filter = proj_filter_textbox.get()
else:
module_filter = name_filter_textbox.get()
get_project(filter=module_filter)
else:
module_filter = name_filter_textbox.get()
get_item()
def main():
drofus_df = Drofus()
drofus_df.mainloop()
if __name__ == "__main__":
main()
请就我是否应该继续使用该类以及“dRofus Module”按钮应该是函数还是类方法提供一些指导。
谢谢你。
okookokokocdkcskcmdfvmfdkvmdfmkvmfdkmvfdkv