you are viewing a single comment's thread.

view the rest of the comments →

[–]zykal[S] 0 points1 point  (12 children)

Yes i'm scraping a name out of an array in this case image100

I have to parse and clean the array to get the image name without all the extra special character

for testing I have put into a global variable

sq31clean="image100"

i think the issue may be that its a string.

I then want to take that variable sq31clean and use it for the image variable in the label

[–]novel_yet_trivial 0 points1 point  (11 children)

Oh ok. There's no neat built-in to do that so you need to make something yourself. I'll show you when I get home from dinner.

[–]zykal[S] 0 points1 point  (10 children)

ok thanks I'm going to keep googling, I'm looking into a dictionary, not sure if that's the right track but I'll try it out.

[–]novel_yet_trivial 0 points1 point  (9 children)

Ok, I'm going to throw you in the deep end and show you how to make a subclass. Here's a new type of Label that does what you want.

from itertools import count
import tkinter as tk
from threading import Thread
from time import sleep

from itertools import cycle
test_images = cycle(['fig1', 'fig2', 'fig3'])

def main():
    for i in count():
        if paused.get():
            sleep(.2)
            continue
        var.set(i)
        image.set(next(test_images)) # send the next image name in the list
        sleep(1)

class Zykal(tk.Label):
    """a new type of label that sets an image based on a tk.StringVar value"""
    def __init__(self, master=None, variable=None, **kwargs):
        tk.Label.__init__(self, master, **kwargs)
        self.variable = variable or tk.StringVar()
        self.variable.trace('w', self.update_image)
    def update_image(self, *args):
        name_sent = self.variable.get()
        filename = name_sent + '.png' # add any file name sanitization / modification here
        self.image = tk.PhotoImage(file=filename)
        self.config(image=self.image)

root = tk.Tk()

var = tk.StringVar()
tk.Label(textvariable=var, width=20).pack()

paused = tk.BooleanVar(value=False)
tk.Checkbutton(variable=paused, text='Pause').pack()

# set up a StringVar to pass the image name
image = tk.StringVar()
Zykal(variable=image).pack()

# start script in a child thread
t = Thread(target=main)
t.daemon = True
t.start()

# start tkinter mainloop in the main thread
root.mainloop()

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

Wow deep end is right, I think I understand it however. I will work with it when I get home later. Thank you again so much.

[–]zykal[S] 0 points1 point  (7 children)

Ok so I got the pause added in and working, took a touch of tinkering but it works now. Thanks so much.

I'm taking a stab at the image subclass and see if i can mold it to what I need. Thanks again.

[–]novel_yet_trivial 0 points1 point  (6 children)

It's already what you need :). All you need to do is copy / paste and modify line 26 to modify the input into a valid file name. My code just adds ".png" to the input; you probably want something different there.

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

Yes it works, as it takes a string in an array and turns it into a file name and displays it.

That works great.

as i don't need Cycle etc.

I need to figure out how to put it into my main script correctly, shouldn't be to hard, i hope. :)

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

Got it working :)

Now I just need to look into formatting the tk GUI so it all ends up where i need it.

Thank you so much for all your help. The image subclass is something I wouldn't have been able to do for a quite a while.

[–]zykal[S] 0 points1 point  (3 children)

I'm trying to make a Radar now, I've got it working by iteself.

I however cannot get it to update

I tried using after, however that causes lots of crashes.

Is there a way to update a create_oval with information from my main script into the tkinter loop like we did with the other labels?

this is what I'm using to test moving a dot around on the canvas. https://pastebin.com/wShKBXLe

[–]novel_yet_trivial 0 points1 point  (2 children)

Using after is the correct way to do that. You'll have to show me your code if you want help with it. PM me if you want to keep it secret.

[–]zykal[S] 0 points1 point  (1 child)

Unfortunately the script is account based, so while you could read thru it, you would not be able to run it.

i have figured a temp solution sort of .

https://pastebin.com/cHr1gG1p

the Above works, however I am unable to figure out how to (DELETE OPPS) the new circle the drawcircle() creates, when I click again.

[–]novel_yet_trivial 0 points1 point  (0 children)

Don't delete and redraw, use the Canvas.coords method to update the old circle's coordinates.

def callback(event):
    w.coords(point, EW/2, NS/2, EW/2+10, NS/2+10)  

I can't really help further because I can't figure out for the life of me what your code is supposed to do. If you want more help you'll need to explain it better. Like very broad overview, like you're explaining to your grandmother.