Python Forum
[Tkinter] adapt management grid mode to management pack mode
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] adapt management grid mode to management pack mode
#5
hi: wuf
I tested the code, and it's worked with success.
could I ask you if it is possible to give a title (according to the name of the image) to the toplevel for each image that corresponds to it

I tried to give a title to the toplevel by modifying the function [def visualize(pil_images, index, event) ]like this:

def visualize(pil_images, index, event):

    zoom_fac = 4
    pil_small_image = pil_images[index]
    image_size = pil_small_image.size
    zoomed_size = [int(side_width*zoom_fac) for side_width in image_size]
    pil_enlarged_image = pil_small_image.resize(zoomed_size)
     
    toplevel = Toplevel() #event.widget)
    toplevel.title("image " + str(index)) # title for toplevel
    toplevel.tk_enlarged_image = ImageTk.PhotoImage(pil_enlarged_image)
     
    Label(toplevel, image=toplevel.tk_enlarged_image).pack()
and I modify the name of the pictures at the code like that :

image_path = "images/test"
image_filenames = ("antennes.png", "far field.png", "unite de distribution.png", "unite de recombinaison.png")
pil_images = list()
tk_images = list()
labels = list() 
  
for index, photo in enumerate(image_filenames):
    photo_name = "\n\n"+ str(image_filenames[index])
    T_generalites_left.insert(END, photo_name,'style_loc35R')
 
    pil_image = Image.open(os.path.join(image_path, image_filenames[index])) 
    pil_images.append(pil_image)
    tk_image = ImageTk.PhotoImage(pil_image)
    tk_images.append(tk_image)
     
    label = Label(T_generalites_left, image=tk_image, cursor='hand1')
    label.bind('<Button-1>', partial(visualize, pil_images, index))
    T_generalites_left.window_create(END, window=label)
I do not know if there is a better idea

thanks for your support
Reply


Messages In This Thread
RE: adapt management grid mode to management pack mode - by atlass218 - Apr-24-2019, 11:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Scaling text QLabel following display mode windows '100%, 125% ...) VIGNEAUD 2 2,317 Jul-07-2021, 06:38 PM
Last Post: deanhystad
  [Tkinter] Text widget inert mode on and off rfresh737 5 4,029 Apr-19-2021, 02:18 PM
Last Post: joe_momma
  [Tkinter] TKK, tree.pack and get size from os diegoctn 2 3,412 Feb-15-2019, 02:38 PM
Last Post: diegoctn
  [Tkinter] Multiple frames with tkinter - How to make them run on fullscreen mode eabs86 3 18,361 Sep-20-2018, 01:27 AM
Last Post: eabs86
  [Tkinter] Treeview automatically adjust it's size when pack inside frame Prince_Bhatia 1 28,123 Jul-25-2018, 03:24 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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