Help Tables python27

Asked

Viewed 1,266 times

5

Good Morning, I’m new with Python/Tkinter and I have some projects in mind, but all of them have use of tables along with them, could anyone tell me if there is a library I could use to create these tables or some way to create them? I tried to use tkintertable but I couldn’t find tutorials on it, I don’t know if it was lack to look for more :/ and I tried to use Tktable too but this is for Python3.x, and I use Python27, I thank you for your attention! Ex: ex:

  • 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)

  • 1

    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!

  • 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.

  • Thank you, I hope to do something because only this problem to solve is missing so I can finish my project ^^!

1 answer

0


Would using a Treeview suit you? It’s not editable as a Datagrid, but you can achieve it in other ways.

Tabela utilizando ttk.Treeview

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()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.