Python Forum
[Tkinter] showing results in TKInter as Vertical List - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] showing results in TKInter as Vertical List (/thread-15467.html)



showing results in TKInter as Vertical List - diegoctn - Jan-18-2019

Hi guys, I am trying to put the result in a label in TKInter but, I am an absolute beginner, I can find the rught way. Practically I'd like to have a list of labels that pick up the result from the win32.

import win32pdh, string, win32api
import tkinter as TT

window = TT.Tk()
window.title ('Power BI')
window.geometry("400x400")

def procids():
    # each instance is a process, you can have multiple processes w/same name
    junk, instances = win32pdh.EnumObjectItems(None, None, 'process', win32pdh.PERF_DETAIL_WIZARD)
    proc_ids = []
    proc_dict = {}
    for instance in instances:
        if instance in proc_dict:
            proc_dict[instance] = proc_dict[instance] + 1
        else:
            proc_dict[instance] = 0
    for instance, max_instances in proc_dict.items():
        for inum in range(max_instances + 1):
            hq = win32pdh.OpenQuery()  # initializes the query handle
            path = win32pdh.MakeCounterPath((None, 'process', instance, None, inum, 'ID Process'))
            counter_handle = win32pdh.AddCounter(hq, path)
            win32pdh.CollectQueryData(hq)  # collects data for the counter
            type, val = win32pdh.GetFormattedCounterValue(counter_handle, win32pdh.PDH_FMT_LONG)
            proc_ids.append((instance, str(val)))
            win32pdh.CloseQuery(hq)
            Lista=(counter_handle,instance, str(val))


    proc_ids.sort()
    return proc_ids

label2 = TT.Label(text=Lista, borderwidth=2, relief="groove")
label2.grid(column=0, row=0)
label2.config(height=2, width=20)
window.configure(background='#ffcc00')
window.mainloop()
Error:
Traceback (most recent call last): File "C:/Users/xxxxx/PycharmProjects/Primo/TaskManager.py", line 33, in <module> label2 = TT.Label(text=Lista, borderwidth=2, relief="groove") NameError: name 'Lista' is not defined



RE: showing results in TKInter as Vertical List - buran - Jan-18-2019

The error is clear. On line 33 when you use Lista it is not defined. Actually it is not defined anywhere. Note that Lista used within procids has local scope. More over you never call that function, i.e. it will not remove the error, but is strange what the purpose is


RE: showing results in TKInter as Vertical List - diegoctn - Jan-18-2019

Thanks Buran and sorry for the bad editing. I am just trying to create a form in TKInter taking the data procids as they are shown in the editor:
import win32pdh, string, win32api
#import tkinter as TT

#window = TT.Tk()
#window.title ('Power BI')
#window.geometry("400x400")

def procids():
    # each instance is a process, you can have multiple processes w/same name
    junk, instances = win32pdh.EnumObjectItems(None, None, 'process', win32pdh.PERF_DETAIL_WIZARD)
    proc_ids = []
    proc_dict = {}
    for instance in instances:
        if instance in proc_dict:
            proc_dict[instance] = proc_dict[instance] + 1
        else:
            proc_dict[instance] = 0
    for instance, max_instances in proc_dict.items():
        for inum in range(max_instances + 1):
            hq = win32pdh.OpenQuery()  # initializes the query handle
            path = win32pdh.MakeCounterPath((None, 'process', instance, None, inum, 'ID Process'))
            counter_handle = win32pdh.AddCounter(hq, path)
            win32pdh.CollectQueryData(hq)  # collects data for the counter
            type, val = win32pdh.GetFormattedCounterValue(counter_handle, win32pdh.PDH_FMT_LONG)
            proc_ids.append((instance, str(val)))
            win32pdh.CloseQuery(hq)
            print(path,instance,type,str(val))


    proc_ids.sort()
    return proc_ids

print (procids())

#label2 = TT.Label(text="XXXXX", borderwidth=2, relief="groove")
#label2.grid(column=0, row=0)
#label2.config(height=2, width=20)
#window.configure(background='#ffcc00')
#window.mainloop()



RE: showing results in TKInter as Vertical List - buran - Jan-18-2019

your procids function should return data you want in a usable format and you will assign the return value to some variable. you will create the GUI and use the data stored in that variable to populate the GUI form


RE: showing results in TKInter as Vertical List - diegoctn - Jan-18-2019

Yes, the result comes like a,b,c,d,e,f,......and I can write the result in a Label but instead I would like to have n label for n "letter"...
I don't know if it is possible.