Reputation: 1622
i have create a botton with Tkinter, like this:
self.calc_amm = Button(self.window)
self.calc_amm["text"] = "Calcola"
self.calc_amm["command"] = lambda: self.testo.insert(1.0, (operazioni.ammortamento(var_sel.get(), self.inserisci_imponibile.get(), self.inserisci_tasso.get(), var_periodo.get(), self.durata.get())))
self.calc_amm.grid(row = 6, column = 0, padx = 2, pady = 2)
where
self.calc_amm["command"] = lambda: self.**testo**.insert(1.0, (operazioni.ammortamento(var_sel.get(), self.inserisci_imponibile.get(), self.inserisci_tasso.get(), var_periodo.get(), self.durata.get())))
"testo" is
self.testo = Text(f)
self.testo["background"] = "white"
self.testo.grid(row = 4, column = 0, columnspan = 4)
The idea is get the value var_sel.get(), self.inserisci_imponibile.get(), self.inserisci_tasso.get(), var_periodo.get(), self.durata.get()
and pass the values to the function operazioni.ammortamento(a,b,c,d,e)
.
In the function operazioni.ammortamento(a,b,c,d,e)
i do some calculations, and return 3 lists (return(arr_rata, arr_quota_cap, arr_cap_res)
).
My output, in the Text widget, is as follows:
{1 2 3 4 5 6 7 8 9 10} {5000 5000 5000 5000 5000 5000 5000 5000 5000 5000} {4500 4000 3500 3000 2500 2000 1500 1000 500 0}
How can I do to have the output like as follows???
Something: Someth.: Someth.:
{1 5000 4500
2 5000 4000
3 5000 3500
4 5000 3000
5 5000 2500
6 5000 2000
7 5000 1500
8 5000 1000
9 5000 500
10} 5000 0
Thank you so much!!
Upvotes: 1
Views: 543
Reputation: 7176
First make it work, then make it beautiful; You have three lists:
arr_rata = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr_quota_cap = [5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000]
arr_cap_res = [4500, 4000, 3500, 3000, 2500, 2000, 1500, 1000, 500, 0]
Making a Text widget as an example:
from tkinter import *
root = Tk()
testo = Text(root, width=40, height=15)
testo.grid(padx=10, pady=10, sticky='nsew')
Print them to Text widget one index at a time:
testo.delete(1.0,END) # Delete text from widget if there is any
testo.insert(END,'rata: quota_cap: cap_res:\n')
for index in range(len(arr_rata)):
col1 = '{:<8}'.format(arr_rata[index])
col2 = '{:<13}'.format(arr_quota_cap[index])
col3 = '{}'.format(arr_cap_res[index])
line = col1 + col2 + col3 + '\n'
testo.insert(END,line)
You can rewrite it with list comprehension or lambda later if you think it's necessary.
Also see The Tkinter Text Widget
Upvotes: 1