Oct-02-2023, 02:03 AM
hello.
I have 2 windows:
a)window = tkinter.Tk(), a mapview and an Entry to write a filepath
b)top=Toplevel() and a label to view an image
I need to pass a dynamic variable (full filepath.i.e.: "d:/bilde/Rød.png" from window a to a PhotoImage function in window b. At present time, without success.
Plan is to make an event (sv), view an image on label,in window b (exactly below an tkintermap in window a).
It works ok as long as I hardcode the filepath in window b.
My doubt is, does the event (sv) trigger the PhotoImage function after I manually write in filepath into an tkinter Entry in window a?
(I might write/read a file to pass variable between windows, but that would be a none alternative and slow process).
Below is some copies of code in each window.
var1 in window a, shows correct path (entered from keyboard)
No image is shown from window b. No errors detected.
SOME CODE IN WINDOW A:
.
.
TOPLEVEL WINDOW:
I have 2 windows:
a)window = tkinter.Tk(), a mapview and an Entry to write a filepath
b)top=Toplevel() and a label to view an image
I need to pass a dynamic variable (full filepath.i.e.: "d:/bilde/Rød.png" from window a to a PhotoImage function in window b. At present time, without success.
Plan is to make an event (sv), view an image on label,in window b (exactly below an tkintermap in window a).
It works ok as long as I hardcode the filepath in window b.
My doubt is, does the event (sv) trigger the PhotoImage function after I manually write in filepath into an tkinter Entry in window a?
(I might write/read a file to pass variable between windows, but that would be a none alternative and slow process).
Below is some copies of code in each window.
var1 in window a, shows correct path (entered from keyboard)
No image is shown from window b. No errors detected.
SOME CODE IN WINDOW A:
import tkinter from Scripts import dati from Scripts import rutiner from tkinter.ttk import * import tkintermapview import customtkinter from tkinter import Canvas from tkinter import * from datetime import datetime from pynput.mouse import Button, Controller import tkinter as tk from PIL import ImageTk, Image import cv2 #---------------------GLOBAL VARIABLES------------------------- mouse = Controller() zoom=1 db = "D:/Python311/Scripts/markers.db" today = datetime.today( ).strftime("%d-%m-%Y-%H-%M-%S") verdi=0 stinavn1="" stinavn2="" stinavn3="" stinavn4="" textentered1="" var1="" root_tk = tkinter.Tk() window = root_tk window.geometry("1920x1200+0+0") window.minsize(1920, 1200) window.resizable(False, False) window.overrideredirect(True) window.attributes('-topmost',True).
.
def callback(sv): textentered1= str(sv.get()) var1 =textentered1 if "htt" in var1:stitype="web" elif ".png" in var1:stitype= "fil" elif ".mp4" in var1:stitype = "vid" elif ".docx" in var1:stiltype = "word" print(var1) sv = StringVar() sv.trace("w", lambda name, index, mode, sv=sv: callback(sv)) sti1 = customtkinter.CTkEntry(window, textvariable=sv, width=360, font=("Ariel",14,"bold"), placeholder_text="Sti til bilde 1 som skal behandles.(d:/bilde/abc.png)", justify=("left")) sti1.place(x=12,y=1010).
.
TOPLEVEL WINDOW:
top = Toplevel() top.geometry("1000x1000") top.resizable(False, False) top.overrideredirect(True) histimg=PhotoImage(file="d:/bilde/Rød.png") (a png image with red circle) label=Label(top,image=histimg) label.place(x=0,y=0) window.mainloop()