【发布时间】:2020-12-13 00:56:09
【问题描述】:
我有一个pandastable,它显示在我的tkinter GUI 中。
使用tkinter 选项菜单中的值value = Status.get() 我想在pandastable 中选择一个特定的单元格,然后使用value = Status.get() 中的值附加该单元格。
我知道如何在函数中使用set_value() 将值附加到dataframe,但我不确定如何使用pandastable 返回所选单元格的位置?或者如果可能的话?
我玩过tkinter treeview 小部件,您可以使用.focus() 返回选定的单元格位置
我一直在使用文档引用方法:https://pandastable.readthedocs.io/en/latest/_modules/pandastable/core.html#Table.get_col_clicked
但我找不到任何适合我的目的......
看下面我的pandastable截图,Column Current Statusrow 2位置已经被双击了。我想回到这个位置。
root = tk.Tk()
root.geometry("2000x1000")
root.title('Workshop Manager')
def select_input_file():
global df, app
input_file_path = filedialog.askopenfilename(filetypes=(("CSV files", "*.csv"),))
app = TestApp(root, input_file_path)
app.place(bordermode=INSIDE, height=500, width=2000, x=0, y=50)
df = app.table.model.df
class TestApp(tk.Frame):
def __init__(self, parent, input_file_path, editable = True, enable_menus = False):
super().__init__(parent)
self.table = Table(self, showtoolbar=False, showstatusbar=False)
self.table.importCSV(input_file_path)
self.table.show(input_file_path)
self.table.addColumn('Current Status')
self.table.addColumn('Assign Technician')
self.table.autoResizeColumns()
def set_cell():
row = app.table.getSelectedRow()
col = app.table.getSelectedColumn()
app.table.model.setValueAt(Status.get(), row, col)
app.table.redraw()
StatusList = [
"Carry Over",
"Waiting On Parts",
"Waiting On Car Wash",
"Yet to Arrive",
"Not Started",
"Being Worked On",
]
Status = StringVar()
Status.set(0)
drop=tk.OptionMenu(root, Status, "Select Status", *StatusList, command = set_cell())
drop.place(x=1440, y=0, height=50, width=150)
root.mainloop()
【问题讨论】:
-
非常有用的线程,很棒的信息。我在其中找不到任何用于此特定目的的东西?我已经用截图更新了问题。希望它能讲述一个更好的故事。再次感谢