Python Forum
[Tkinter] showing results in TKInter as Vertical List
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] showing results in TKInter as Vertical List
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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()
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] tkinter menubar not showing on mac ventura taras 1 2,043 Dec-17-2022, 02:44 PM
Last Post: Yoriz
  tkinter showing image in button rwahdan 3 5,528 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  [Tkinter] Tkinter Textbox only showing one character Xylianth 1 2,142 Jan-29-2021, 02:59 AM
Last Post: Xylianth
  [Tkinter] Vertical Tabs Alignment in Tkinter muhammadasim 2 5,913 Oct-05-2020, 08:40 AM
Last Post: Larz60+
  How to display results from terminal window onto tkinter. buttercup 0 3,603 Jul-21-2020, 04:41 AM
Last Post: buttercup
  [Tkinter] Entry box not showing 2 decimal places Chuck_Norwich 3 5,618 Apr-24-2020, 05:28 PM
Last Post: deanhystad
  Require scroll bars horizontal and vertical throughout the window tejgandhi 2 2,675 Jun-28-2019, 03:13 AM
Last Post: tejgandhi
  [Tkinter] Tkinter optionmenu child menu position showing 0,0 thatguy14 2 4,590 Jun-15-2018, 10:42 AM
Last Post: thatguy14

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020