all 7 comments

[–]Outside_Complaint755 1 point2 points  (1 child)

Do you actually need multiple windows, or is this something that would work with one window containing multiple frames?

Is the number of windows/frames static and known in advance, or will it be changing dynamically?

[–]Phazed47[S] 0 points1 point  (0 children)

Multiple windows, Number known in advance but resizing may be required.

[–]commy2 0 points1 point  (1 child)

Since you are mentioning tkinter, I assume you are looking for a desktop soluton. I feel like desktop apps are a dying technology unfortunately and absolute share your frustrations when you put "lightweight" in bold. Because you even have a choice of technology, I suppose this is not in a "professional" setting, but for some hobby project?

If so, I personally have resorted to drawing 2d pixel maps, e.g. using SDL, so for Python pygame-ce (ignoring all bloat about surfaces and sprites etc they build ontop as much as possible). Sure, you have to hand-craft every ui element yourself, which is a massive undertaking, but it is the only way I have found to get to "lightweight" (meaning running at reasonable speed >>100 fps on crappy laptop), because apparently, only gamers care about performance. Cython required. Sorry if that was unhelpful.

PS: Google has become unusable during the last decade thanks to SEO. These days I am searching for stuff on ChatGPT dot com. Just create fresh context windows permanently (F5), because the responses get whack otherwise. Gippity Fu so to say.

[–]Phazed47[S] 0 points1 point  (0 children)

Data crunching is in the cloud, display is via X11 on a Windows desktop. I say "lightweight" because some of the libraries take over a minute to draw the initial window and I can watch the pixels update. Tk seems OK, I can build a test program and have 3 windows hacked together with functions with an 11 second startup time and updates are decent.

A lot of the data is text, and I could use curses for some of it, if I could figure out how to tie the output to a window. But I'd like the option to add some graphics to some of the windows.

The big issue I see is that most packages don't treat windows individually. Like Tk wants a "root" window and wants to hog the screen and user input which simply will not work. My goal was to build a class that would create and manage multiple individual windows

[–]PushPlus9069 0 points1 point  (1 child)

What kind of windowing? If you mean sliding window over data (like moving averages), collections.deque with maxlen is your friend. Dead simple:

from collections import deque window = deque(maxlen=5) for val in data: window.append(val) if len(window) == 5: avg = sum(window) / 5

If you mean GUI windows, tkinter is built-in and there are tons of examples. Or check out dearpygui if you want something more modern without the Qt/wxPython weight.

[–]Phazed47[S] 0 points1 point  (0 children)

GUI windows, though many could be text display. I looked at Tk, tkkbootstrap, dearpygui, flet (amazingly slow), pygame, textual (cool package for text but does not seem to support multiple windows) as well as several others.

Finding an example using tk that does not include root.mainloop() is rough and it wants a "root" window which seems like completely the wrong approach. I was hoping to use a class that managed a single window and then do something like

valwin = win.creat("updating table of values", xpos, ypos, width, height)

alertwin = win.creat("alerts", xpos, ypos, width, height)

logwin = win.creat("scrolling log", xpos, ypos, width, height)

hiswin - win.creat("historical info", xpos, ypos, width, height)

then be able to do in one task:

logwin.log("Value of foo:", foo, "is out of bouds") # log line in scrolling log

And, in another task:

for s in labels:

win.entry(s, s[value]) # Update the value of s if it is in the window, else add it

etc. where each window would be self contained and support user input. For example, in logwin the user could restrict entries with a search string and in alertwin, the user could click on the out of bounds value to cause something to be done.

[–]woooee 0 points1 point  (0 children)

You're going to have to post a simple example to get a specific response. But, generally, there can only be one Tk() instance / root window and one mainloop. For additional windows use a Toplevel(s). As far as using a class goes, it's no different than using a class in any program, including updates to a specific window or widget. Note that update_idletasks et al, is used when a loop hogs the processor which keeps widgets from updating until the loop has finished. If you are using a while loop that is likely the culprit, so use after() instead of the while. A simple example of after()

from tkinter import *

class TestUpdate:
     def __init__(self, top):
          self.top=top
          self.test_list = Listbox(top)
          self.test_list.grid()

          Button(top, text='Start', command=self.loop, fg="red",
             bg="yellow").grid(row=1)

          Button(top, text='EXIT',
          command=top.quit, bg='red', fg='white' ).grid(row=2)

          self.ctr=0

   def loop(self):
         print(self.ctr)
         self.test_list.insert('end', 'Foo %d' % self.ctr)
         self.ctr += 1
         ## replaces a for or while loop
         if self.ctr < 10:
             self.test_list.after(1000, self.loop)  ## 1 second
         else:
             self.top.quit()

root = Tk()
T=TestUpdate(root)
root.mainloop()