简体   繁体   English

如何在 Python 的 GUI 中打印字典中的所有值

[英]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.好吧,如果您想跟踪所有客户和月份(我假设它们与clientemes相同),那么您必须全部跟踪它们。 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.

相关问题 如何从 Python 中的字典中提取所有值? - How can I extract all values from a dictionary in Python? 如何从Python中的嵌套字典中一起打印所有键和值? - How to print all the keys and values together from a nested dictionary in Python? 如何添加所有键的值并打印新词典? - How can I add all keys' values and print the new dictionary? 如何从python中的图像在GUI中打印值? - How to print values in GUI from image in python? 如何在 Python 中打印字典键值的平均值? - How can I print the mean of key values of a dictionary in Python? 如何用一系列值替换 Python 字典的所有值? - How can I replace all the values of a Python dictionary with a range of values? 如何从另一个python字典中的一个字典中获得相应的列表值,在列表中它们被列为键,比较并打印出csv? - How can I get corresponding list values in one dictionary from another python dictionary where they are listed as keys, compare and print out a csv? 如何在python中仅打印字典的所有值? - How to print only print all the values of a dictionary in python? Python:如何从字典中打印某些值 - Python: How to print certain values from a dictionary Python 中的 Discord ChatBot:如何从字典中打印某些内容? - Discord ChatBot in python: How can I print something from a dictionary?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM