Display of a dropdown menu in pandastable

  pandas, python, tkinter

I am visualizing my pandas dataframe with pandastable to look at the data and modify it there. This works as planned. Now I want to extend the code to show me a dropdown menu, when I edit the cell in the displayed pandastable. The dropdown menu should present default values that are allowed as cell values. For example, for column 1 of the Dataframe possible values are 1,2 and 3. Does anyone have any idea how I can achieve this.

I would like to extend the following code:

import tkinter as tk
import sqlite3
from pandastable import Table
import pandas as pd

def save():
    df.to_sql("crawled", conn, if_exists="replace")
    print(df)
    root.quit()

root = tk.Tk()
root.geometry("1500x1000")

frame = tk.Frame(root)
frame.pack(fill="both", expand=True)

df = pd.DataFrame()
df["column1"] = [1,2,3]
df["column2"] = ["a","b","c"]

conn = sqlite3.connect("99_data_increment.db")

pt = Table(frame, dataframe=df, width=300)
pt.show()

button = tk.Button(root, text="Save edits", command=save)
button.pack()

root.mainloop()

Source: Python Questions

LEAVE A COMMENT