Would using a Treeview suit you? It’s not editable as a Datagrid, but you can achieve it in other ways.
That code is amply post-based Tkinter Multi-column List Demo (suggest a visit):
import Tkinter as tk
import ttk
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.set_widgets()
def set_widgets(self):
# Inicia o Treeview com as seguintes colunas:
self.dataCols = ('country', 'capital', 'currency')
self.tree = ttk.Treeview(columns=self.dataCols, show='headings')
self.tree.grid(row=0, column=0, sticky=tk.N + tk.S + tk.W + tk.E)
# Barras de rolagem
ysb = ttk.Scrollbar(orient=tk.VERTICAL, command=self.tree.yview)
xsb = ttk.Scrollbar(orient=tk.HORIZONTAL, command=self.tree.xview)
self.tree['yscroll'] = ysb.set
self.tree['xscroll'] = xsb.set
ysb.grid(row=0, column=1, sticky=tk.N + tk.S)
xsb.grid(row=1, column=0, sticky=tk.E + tk.W)
# Define o textos do cabeçalho (nome em maiúsculas)
for c in self.dataCols:
self.tree.heading(c, text=c.title())
# Dados:
self.data = [
("Argentina", "Buenos Aires", "ARS"),
("Australia", "Canberra", "AUD"),
("Brazil", "Brazilia", "BRL"),
("Canada", "Ottawa", "CAD"),
("China", "Beijing", "CNY"),
("France", "Paris", "EUR"),
("Germany", "Berlin", "EUR"),
("India", "New Delhi", "INR"),
("Italy", "Rome", "EUR"),
("Japan", "Tokyo", "JPY"),
("Mexico", "Mexico City", "MXN"),
("Russia", "Moscow", "RUB"),
("South Africa", "Pretoria", "ZAR"),
("United Kingdom", "London", "GBP"),
("United States", "Washington, D.C.", "USD"),
]
# Insere cada item dos dados
for item in self.data:
self.tree.insert('', 'end', values=item)
if __name__ == '__main__':
root = tk.Tk()
app = Application(master=root)
app.mainloop()
When you say "tables" you mean graphical interface elements that represent tables, right? (e.g.: spreadsheet, datagrid...) And you’re using Tkinter on your system, right? It is good to add these details to the question, because the way it is became a little vague... (at first reading I thought they were database tables)
– mgibsonbr
Good morning my dear friend, I’m sorry I left such a vague question, but I don’t mean database tables, but spreadsheet tables like Excel, do you understand? I want the following to do a database search and have a return on these tables. ex: |product |ncm |ean | |rice |1245565|154487| Putz am terrible with this lol editor but the rice table should be below the products table!
– dhelbegor
Thanks for the clarifications! For now, I do not have an answer to give you, but later I will do a research and return to this question.
– mgibsonbr
Thank you, I hope to do something because only this problem to solve is missing so I can finish my project ^^!
– dhelbegor