[英]How can i print all values from a dictionary in a GUI in Python
I am developing an application to enter a spreadsheet, check customers who have not paid the fee, list them in a dictionary and then print them out in a graphical interface made in Tkinter.我正在开发一个应用程序来输入电子表格,检查未支付费用的客户,在字典中列出他们,然后在 Tkinter 制作的图形界面中打印出来。 The code itself works, my problem here is that it only prints the last value of the dictionary in the graphical interface.
代码本身有效,我的问题是它只在图形界面中打印字典的最后一个值。
Here is the code below:下面是代码:
from tkinter import *
import openpyxl
root = Tk()
def func():
newWindow = Toplevel()
newWindow.title("Output")
newWindow.geometry("400x500+375+50")
# Opens the spreadsheet and obtains the status of the last payment.
wb = openpyxl.load_workbook('C:/temp/cobranca.xlsx')
sheet = wb['Sheet1']
lastCol = sheet.max_column
# latestMonth = sheet.cell(row=1, column=lastCol).value
# Checks the payment status of each customer.
unpaidMembers = {}
for r in range(2, sheet.max_row + 1):
for c in range(3, lastCol + 1):
payment = sheet.cell(row=r, column=c).value
if payment != 'ok':
cliente = sheet.cell(row=r, column=1).value
email = sheet.cell(row=r, column=2).value
mes = sheet.cell(row=1, column=c).value
unpaidMembers[cliente] = email
print('Line:', r, 'Column:', c, 'Client:', client, 'Email:', email, 'Month:', month)
#--- LABELS ---#
l_label1 = Label(newWindow, text="Client", font='-weight bold')
l_label1.grid(row=1, column=1)
l_label2 = Label(newWindow, text="Competence", font='-weight bold')
l_label2.grid(row=1, column=2)
v_result1 = StringVar()
l_cliente = Label(newWindow, textvariable=v_result1)
l_cliente.grid(row=2, column=1)
v_result2 = StringVar()
l_mes = Label(newWindow, textvariable=v_result2)
l_mes.grid(row=2, column=2)
# --- VARIABLES --- #
result1 = client
result2 = month
#--- OUTPUT ---#
v_result1.set(result1)
v_result2.set(result2)
bt = Button(root, text='Check', command=func)
bt.grid(row=1, column=1)
root.mainloop()
Spreadsheet template i'm using: https://prnt.sc/123qzfv我正在使用的电子表格模板: https://prnt.sc/123qzfv
Can you help me?你能帮助我吗?
Well, if you want to track ALL the clients and months (which I assume are the same as cliente
and mes
), then you have to tracek them all.好吧,如果您想跟踪所有客户和月份(我假设它们与
cliente
和mes
相同),那么您必须全部跟踪它们。 Something like this:像这样的东西:
...
# Checks the payment status of each customer.
unpaidMembers = {}
clients = []
months = []
for r in range(2, sheet.max_row + 1):
for c in range(3, lastCol + 1):
payment = sheet.cell(row=r, column=c).value
if payment != 'ok':
cliente = sheet.cell(row=r, column=1).value
email = sheet.cell(row=r, column=2).value
mes = sheet.cell(row=1, column=c).value
clients.append( cliente )
months.append( mes )
unpaidMembers[cliente] = email
print('Line:', r, 'Column:', c, 'Client:', client, 'Email:', email, 'Month:', month)
#--- LABELS ---#
l_label1 = Label(newWindow, text="Client", font='-weight bold')
l_label1.grid(row=1, column=1)
l_label2 = Label(newWindow, text="Competence", font='-weight bold')
l_label2.grid(row=1, column=2)
v_result1 = StringVar()
l_cliente = Label(newWindow, textvariable=v_result1)
l_cliente.grid(row=2, column=1)
v_result2 = StringVar()
l_mes = Label(newWindow, textvariable=v_result2)
l_mes.grid(row=2, column=2)
#--- OUTPUT ---#
v_result1.set('\n'.join(clients))
v_result2.set('\n'.join(months))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.