-2

Trying to split my parent window in several functional parts, one of which will be dealing with weather data and etc and another one will be located in the right side and contain the map image, preferably extending at full height. The image doesn't want to come up though.. Please help

import pyowm
from tkinter import *
import tkinter.messagebox
from PIL import Image, ImageTk

owm = pyowm.OWM('....')  # You MUST provide a valid API key
class MyWindow(tkinter.Frame):
    def __init__(self, win):
        super(MyWindow, self).__init__()
        self.lbl=Label(win, text="Weather info", fg='black', font=("Helvetica", 11))
        self.lbl1=Label(win, text='Wind speed')
        self.lbl2=Label(win, text='Wind direction')

        self.lbl.grid(row = 0, column = 0, sticky =  W, pady = 2) 
        self.lbl1.grid(row = 1, column = 0, sticky = W, pady = 2)
        self.lbl2.grid(row = 2, column = 0, sticky = W, pady = 2)

        # widgets for destination and weather output
        self.e1=Entry()
        self.e2=Entry()
        self.e3=Entry(bd=3)

        # this will arrange entry widgets 
        self.e1.grid(row = 0, column = 1, pady = 2) 
        self.e2.grid(row = 1, column = 1, pady = 2)
        self.e3.grid(row = 2, column = 1, pady = 2)

        self.btn1 = Button(win, text='Get weather', command=self.getWeather)
        self.btn1.grid(row = 3, column = 1, pady = 2)

        self.btn1.bind('<Button-1>', self.getWeather)

        img = Image.open(r"/User/.../pic.png")
        photo = ImageTk.PhotoImage(img) 

        # setting image with the help of label 
        self.imgLBL = Label(self, image = photo)
        self.imgLBL.grid(row = 0, column = 2, columnspan = 2, rowspan = 2, padx = 5, pady = 5)
        self.imgLBL.image = photo

    #### Get weather function, etc...###

window=Tk()
mywin=MyWindow(window)
window.title('name')
window.geometry("2732x2048")
window.configure(bg='grey')
window.mainloop()
  • 1
    Does [this](http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm) or [this](https://stackoverflow.com/questions/16424091/why-does-tkinter-image-not-show-up-if-created-in-a-function) help? – kusz Mar 11 '20 at 13:29

1 Answers1

0

Replace last few lines with this:

self.photo = ImageTk.PhotoImage(Image.open(r"/User/.../pic.png"))

# setting image with the help of label
self.imgLBL = Label(window, image=self.photo)
self.imgLBL.grid(row = 0, column = 2, columnspan = 2, rowspan = 2, padx = 5, pady = 5)
self.imgLBL.image = self.photo
Zaraki Kenpachi
  • 5,510
  • 2
  • 15
  • 38
  • I really appreciate! The image is there now, just that it appeared right at the center of the window and squeezed everything on the left, only 1 Entry window is visible now and it was pushed down the middle.. – Olexiy Usov Mar 11 '20 at 13:51
  • @Olexiy Usov you need to rearrange positions of you elements, or make span few rows for image. – Zaraki Kenpachi Mar 11 '20 at 13:53
  • Thank you! Yes I'm working on re-arranging the elements. – Olexiy Usov Mar 11 '20 at 17:09