'get method for Tkinter GUI from a list of dictionaries
I need your help again. the problem is on x1=entries[g].actions.get("Desc") Obviously i dont call the value of the dictionary "Desc" correctly. I have run the rest and it seems to work fine. I cant figure out how i will get the user values for my document though.
from docx import Document
from tkinter import *
from tkinter import ttk
w = Tk()
actions = {"Desc":[],"Cau":[],"Met":[]}
entries = [actions]
count = 0
def add():
global count
actions["Desc"].append(ttk.Combobox(w, value = o1).grid(row=0,column=count))
actions["Cau"].append(ttk.Combobox(w, value =op2).grid(row=1,column=count))
actions["Met"].append(ttk.Combobox(w, value = op3).grid(row=2,column=count))
entries[-1]
count += 1
def generate():
document = Document()
table = document.add_table(rows=count1, cols=4)
hdr_cells = table.rows[0].cells
hdr_cells[0].paragraphs[0].add_run('Title')
g=0
for actions in range(len(entries)):
col_cells= table.rows[g+1].cells
x1=entries[g].actions.get("Desc")
x3=entries[g].actions.get("Cau")
x4=entries[g].actions.get("Met")
col_cells[0].paragraphs[0].add_run(x1)
col_cells[2].paragraphs[0].add_run(x3)
col_cells[3].paragraphs[0].add_run(x4)
g+=1
document.save('test.docx')
btn = Button(w,text='genarate docx', command=generate).grid(row=4,column=0)
b_res = Button(w, text = "add", command= add).grid(row=3,column=0)
op1 = ["sa", "sdg"]
op2= ["to", "dam", "scr"]
op3 = ["rep", "repla", "r"]
w.mainloop()
Thanks for any help!!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|