Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Unable fetch fucntion data in class in tkinter
I am trying to fetch the data from text variable and image data in a function name loopCap and display it in __init__ function where I have created a canvas but due to mentioned below error I am not able to move further

Update: I was able to update the text but Image is still the major issues

For Text Error:

*(args + self._options(cnf, kw))))
_tkinter.TclError: unknown option "-textvariable"
For Image Error:

self.put_photo = canvas.create_image(70, 250,, anchor='nw')
AttributeError: 'StartPage' object has no attribute 'photo'
Actual Code Sample:

import tkinter as tk
from tkinter import *
from tkinter.filedialog import asksaveasfile
from tkinter import messagebox
from PIL import ImageTk, Image

im = "BG.jpg"
class SampleApp(tk.Tk):
    def __init__(self):
        self._frame = None
        self.ard_stat = read_json(JSON_PATH)

    def switch_frame(self, frame_class):
        """Destroys current frame and replaces it with a new one."""
        new_frame = frame_class(self)
        if self._frame is not None:
        self._frame = new_frame

class StartPage(tk.Frame):

    def loopCap(self):
        with open(JSON_PATH) as json_file1:
   = json.load(json_file1)
        if['status'] == 'ACTIVE':  # and (['RH_img']!= 'null' or['LH_img']!= 'null')
            a = self.text.set(['status'])
         if['RH_img'] == 'NA':
         self.img =
         self.img.load() = ImageTk.PhotoImage(self.img)
       self.label['image'] =
       self.master.after(500, self.loopCap)

 def __init__(self, master):
        Frame2 = tk.Frame(self.master)
        Frame2.pack(fill='both',expand = True)
        self.photo_back = ImageTk.PhotoImage(im)
        lab_1 = tk.Label(Frame2, image=self.photo_back)
        lab_1.image = self.photo_back, y=0, relwidth=1, relheight=1)
        canvas = Canvas(Frame2, width=1000, height=700), y=0, relwidth=1, relheight=1)
        canvas.create_image(0, 0, image=self.photo_back, anchor='nw')
        self.text = tk.StringVar()
        canvas.create_text(230, 170, fill="white", font="Times 20 bold", 
        textvariable=self.text, anchor="w")
        self.label = tk.Label(canvas)
        self.put_photo = canvas.create_image(70, 250,, anchor='nw')
        self.master.after(500, self.loopCap)

if __name__ == "__main__":
    app = SampleApp()
text variables need to be of type StringVar()
fetch value with varname.get
Hi, I was able to update the text data using canvas.itemconfig() but still facing the issue of calling image data from loopCap function in __init__ function as I have edited my main question and updated the image error which I am still facing there.
Please help me in resolving this issue. Will be very helpful

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Fetch records from DB and display on GUI hnkrish 1 157 Dec-05-2019, 02:38 PM
Last Post: Denni
  Unable to put background image on Tkinter Frame jenkins43 2 518 Nov-27-2019, 11:38 AM
Last Post: jenkins43
  Tkinter Class pythonenthusiast2 1 183 Nov-24-2019, 03:51 AM
Last Post: Larz60+
  [Tkinter] Plotting Raster Data / TIFF files on tkinter canvas RRSCNGP 0 280 Aug-28-2019, 04:44 AM
Last Post: RRSCNGP
  Unable to update or refresh label text in tkinter jenkins43 3 955 Jul-24-2019, 02:09 PM
Last Post: Friend
  TKinter GUI / Pandas Data frame Loop NSearch 0 1,341 Jun-26-2019, 12:37 AM
Last Post: NSearch
  Tkinter Gui ScrolledText Insert From Different Class whisperquiet 1 1,215 Jan-08-2019, 09:25 PM
Last Post: Larz60+
  [Tkinter] Unable to Obtain values from one Tkinter Program into another nilaybnrj 1 615 Aug-24-2018, 01:24 PM
Last Post: Gribouillis
  Unable to return value from callback function of a button in Python Tkinter nilaybnrj 4 8,323 Aug-05-2018, 11:01 PM
Last Post: woooee
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 3,955 Mar-27-2018, 11:44 AM
Last Post: nortski

Forum Jump:

Users browsing this thread: 1 Guest(s)