How to call data from a dictlist into code in the form of Checkbutton in python Tkinter

Asked

Viewed 28 times

1

Reformulating everything, I created a new file from scratch called "dict_list_codigopenal.py", he is responsible for taking the file "cdp.csv" and read as spreadsheet, transforming into a Dict list. However, I really need to create a graphical interface of this with Tkinter. I want to know how to call the data of a dictlist into the other code in the form of Checkbutton? For example, all checkbuttons linked by the "Articles" of the penal code.

Follow the codes below:

dict_list_codigopenal.py:

import csv
import json

def exportar():
    with open('cdp.csv', encoding="utf8",mode='r') as csv_file:
        csv_reader = csv.DictReader(csv_file)
        infracoes = list()
        for row in csv_reader:
            infracoes.append(row)
#        print(json.dumps(infracoes, indent=4, ensure_ascii=False).encode("utf8").decode("utf8"))
    return infracoes

infracoes = exportar()

central_cp_inova.py:

import dict_list_codigopenal
from tkinter import *
from tkinter import ttk
import tkinter as tk
import json

def defocus(event):
    event.widget.master.focus_set()

# start of GUI code
root = Tk()
root.title('Sistema de Código Penal - Cidade iNova')
root.resizable(0,0)

# start of Notebook (multiple tabs)
notebook = ttk.Notebook(root)
notebook.pack(fill=BOTH, expand=True)
notebook.pressed_index = None

# Child frames
Container1 = Frame(notebook)
Container1.pack(fill=BOTH, expand=True)
Container2 = Frame(notebook)
Container2.pack(fill=BOTH, expand=True)

# Create the pages
notebook.add(Container1, text='Infrações')
notebook.add(Container2, text='Calcular')

canvas1 = Canvas(Container1, width=1200, height=450)
scroll = Scrollbar(Container1, command=canvas1.yview)
canvas1.config(yscrollcommand=scroll.set, scrollregion=(0,0,100,1400))
canvas1.pack(side=LEFT, fill=BOTH, expand=True)
scroll.pack(side=RIGHT, fill=Y)
canvas2 = Canvas(Container2, width=1200, height=450)
scroll = Scrollbar(Container2, command=canvas2.yview)
canvas2.config(yscrollcommand=scroll.set, scrollregion=(0,0,100,1000))
canvas2.pack(side=LEFT, fill=BOTH, expand=True)
scroll.pack(side=RIGHT, fill=Y)

frame1 = Frame(canvas1, width=800, height=450)
canvas1.create_window(300, 700, window=frame1)

frame2 = Frame(canvas2, width=800, height=450)
canvas2.create_window(200, 140, window=frame2)

# Main Frame

#Close Application Button
def quit(root):
    root.destroy()


ttk.Button(root, text="Fechar Aplicativo", command=lambda root=root:quit(root)).pack()

if __name__ == '__main__':

    a = print(json.dumps(dict_list_codigopenal.infracoes, indent=4, ensure_ascii=False).encode("utf8").decode("utf8"))

    mylabel = Label(frame1, text=dict_list_codigopenal.infracoes.get()).pack()

    root.mainloop()
No answers

Browser other questions tagged

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