0

I'm working on thermography camera and i making the interface. I face some error that my textvariable won't print in the tkinter but still can be printed on the shell. What is wrong with my code?

import pandas as pd
import cv2
import matplotlib.pyplot as plt
from tkinter import *
from tkinter.filedialog import askopenfilenames

# List of list
images = []
gs = []
B = []
G = []
R = []
suhu = []
suhuo = []
red = []
green = []
blue = []
waktu = []
utama = Tk()

# Fungsi-fungsi
def mouseRGB(event,x,y,flags,param):
    global gambar
    if event == cv2.EVENT_LBUTTONDOWN: 
        colorsB = gambar[y,x,0]
        colorsG = gambar[y,x,1]
        colorsR = gambar[y,x,2]
        R.append(colorsR)
        G.append(colorsG)
        B.append(colorsB)

def Tutup ():
    utama.destroy()

def tolong ():
    messagebox.showinfo('Help','Jika terjadi error atau kesulitan dalam menggunakan program ini dapat menghubungi 08111903747')

def loadImages ():
    global wkt
    global gambar
    global tem
    wkt = float(wktu.get())
    Gambar = askopenfilenames(parent=jwaktu,
                                 title='Select a thermal image file',
                                 filetypes=[('JPG File','*.jpg'),
                                            ('PNG File','*.png'),
                                            ('All Files','*')])
    # Tutorial pake aplikasi
    messagebox.showinfo('How to use','After clicking or dragging the selected picture, press S for next image')

    # Program olah suhu
    # Perintah Load gambar ke python
    filenames = Gambar
    # Jendela Mouse
    cv2.namedWindow('mouseRGB')
    cv2.setMouseCallback('mouseRGB',mouseRGB)
    time = 0
    for file in filenames:
        gambar = cv2.imread(file)
        time += wkt
        cv2.imshow('mouseRGB',gambar)
        while(1):
            if cv2.waitKey(0) & 0xFF == ord('s') :
                for r in R:
                    red.append(float(r))
                for g in G:
                    green.append(float(g))
                for b in B:
                    blue.append(float(b))
                nr = [i * 0.020411398053616 for i in red]
                ng = [j * -0.01805397732321 for j in green]
                nb = [k * -0.06212844019856 for k in blue]
                R.clear()
                G.clear()
                B.clear()
                red.clear()
                green.clear()
                blue.clear()
                lum = nr + ng + nb 
                lumi = sum(lum)
                tem = lumi + 34.9927907296913
                if tem >= 33.0 and tem<= 39.0:
                    suhuo.append(tem)
                    waktu.append(time)
                suhu.append([file,time,tem])
                SuhuA = Label(jwaktu,textvariable = tem)
                SuhuA.grid(column=1, row = 1)
                print(tem)
                break

    cv2.destroyAllWindows()

    # Olah grafik
    plt.plot(waktu,suhuo)
    plt.xlabel('Waktu (s)')
    plt.ylabel('Suhu (C)')
    plt.title('Sebaran suhu')
    plt.savefig('Sebaran_suhu.png')
    plt.show()
    # Masukan data kedalam csv
    img_df = pd.DataFrame(suhu ,columns = ['Image','Waktu','Temperature'])
    img_df.to_csv('Olah_Suhu.csv')
    waktu.clear()
    suhuo.clear()


def TIP ():
    global SuhuA
    global wktu
    global jwaktu
    jwaktu = Tk()
    jwaktu.title('Thermal Image Processing')
    jwaktu.geometry('600x400')
    Tulisanw = Label(jwaktu,text='Enter the sampling time : ')
    Tulisanw.grid(column = 0 , row = 0)
    wktu = Entry(jwaktu,width = 10)
    wktu.grid(column = 1, row = 0)
    tombolw = Button(jwaktu,text='Execute',command=loadImages)
    tombolw.grid(column = 2, row = 0)
    Suhu = Label(jwaktu,text='Temperature Point   : ')
    Suhu.grid(column = 0, row = 1)
    jwaktu.mainloop()
    return wktu


# Window GUI
utama.title('TCI - Thermograpgy Camera Interface')
utama.geometry('600x400')
menu = Menu(utama)
program = Menu(menu)
program.add_command(label = 'Close',command=Tutup)
menu.add_cascade(label='File', menu=program)
menu.add_command(label = 'Help',command=tolong)
utama.config(menu=menu)
TombolTIP = Button(utama,width=30,text='Thermal Image Processing',command=TIP)
TombolTIP.grid(padx = 200,pady = 50)
TombolRTM = Button(utama,width=30,text = 'Realtime Thermal Measurment')
TombolRTM.grid(padx=200,pady=150)
utama.mainloop()

When i was executing on the other window the temperature point did not show anything. I have already tried to use 'text' instead of 'textvariable', but nothing happened. Thank you for your help!

  • Read [While Loop Locks Application](https://stackoverflow.com/questions/28639228/python-while-loop-locks-application) – stovfl Dec 27 '19 at 10:59
  • Thanks for the advice, actually i already know that the problem is i have 2 root window and somehow it doesn't work that way. After i delete the other root window than the problem solved. Thanks – Ilham pratama Dec 30 '19 at 11:50
  • Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) – stovfl Dec 30 '19 at 12:00

0 Answers0