Home > Back-end >  Show results of Jupyterlab on Tkinter UI
Show results of Jupyterlab on Tkinter UI

Time:09-27

I am currently working on building an UI to show the images in my JupyterLab to my Tkinter UI, that is running on a same script. In my script, I hope that after entering the values in Tkinter, it will take in the input and run again, and show the image on Tkinter UI again, so that I can do try and error. Can anyone guide me or give me a little tips to know where to find the answer and how to work on it?

from tk import *
from tkinter import ttk
from PIL import ImageTk, Image
import tkinter as tk
import os
window = tk.Tk()

def show_result(a,b,c,d):
    #display the image result
    #run the again to test the result
    
x1 = tk.IntVar()
x2 = tk.IntVar()
y1 = tk.IntVar()
y2 = tk.IntVar()

# set textbox to capture variables 
x1_value = ttk.Entry(textvariable=x1).place(x=50, y=50)
x2_value = ttk.Entry(textvariable=x2).place(x=50, y=100)
y1_value = ttk.Entry(textvariable=y1).place(x=50, y=150)
y2_value = ttk.Entry(textvariable=y2).place(x=50, y=200)
    
display_button = ttk.Button(text="Run", command= lambda: show_result(x1.get(),x2.get(),y1.get(),y2.get())).place(x=50, y=300)

window.geometry("900x750")
window.mainloop( )

CodePudding user response:

plt.figure(figsize = (50,8))
plt.imshow(crop_img, cmap='gray')
fig1 = plt.gcf()
fig1.savefig('crop_img.png', dpi=100)
open_img()

# Open img to show on tkinter 
def open_img():
    x = 'crop_img.png'
    img = Image.open(x)
    left=2000
    top=0
    right=3000
    bottom=800
    img = img.crop((left, top, right, bottom))
    img = img.resize((800, 600), Image.ANTIALIAS)
    img = ImageTk.PhotoImage(img)
    panel = Label(window, image=img)
    panel.image = img
    panel.place(x=200, y=0)
  • Related