Help tables python27

5

Good morning, I'm new to Python / Tkinter and I have some projects in mind, but they all have tables using them, could anyone tell me if some library I could use to create these tables or some way to create them? I tried to use tkintertable but I did not find tutorials about it, I do not know if there was a lack of searching for it: /, and I also tried using Tktable but this one is for Python3.x, and I use Python27, thanks in advance! Ex:

    
asked by anonymous 01.07.2014 / 14:12

1 answer

0

Using a Treeview would suit you? It is not editable as a DataGrid, but you can achieve this in other ways.

Thiscodeisextensivelybasedonthepost Tkinter Multi-Column List Demo (I 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()
    
15.08.2014 / 19:59