0

i am newish to python specifically in Tkinter and i want to make a script that opens up a window where you can enter a value that opens up a subwindow with a picture as background and a rectangle of specific format is drwan on the image.

I did do already some coding but its not comming out like i want it to. Iwant the script to import a picture in the window, as first part of the question. I also want it to take my entry-widget values and display them on the sub-window. I can do it with absolut values but if i let the user but in the values i dont get them to transver and draw a rectangle, like if i give the function absolut values or preset variables.

from tkinter import *
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd

def ROI(startx=50):
    ROI_check=Toplevel(root)
    ROI_check.title('ROI Peek')
    ROI_check.geometry('800x500')
    ROI_check.resizable(width=False,height=False)
    canvas = tk.Canvas(ROI_check,width=800,height=500)
    # canvas.grid()
    ROI_image= ImageTk.PhotoImage(Image.open('af.tif')) #create background of this picture (some arbitrary image)
    canvas.create_image(10,10,anchor= NW,image=ROI_image)
    canvas.create_rectangle(startx,startx*2, startx*2, startx*3, outline='red') # create rectangle from entry-values
    canvas.grid()

def Get_entry():
    startx= startx_entry.get()
    startx_var.set(startx)
    return startx_var

def ROI_peek(start=50):
    Get_entry()
    ROI(start)

root = tk.Tk()

root.title("GoDS-Tool")
root.geometry('1300x550')
root.minsize(width=1300,height=500)

startx_entry=StringVar()
startx_var=StringVar()


startx_entry = ttk.Entry(root)
startx_entry.grid(column=1, row=1, sticky=tk.W, padx=5, pady=5)

button_peek = ttk.Button(root, text='Peek',command=ROI_peek)
button_peek.grid(column=2, row=1,  padx=10)

root.mainloop()
Emco Tec
  • 1
  • 1
  • 1
    *"its not comming out like i want it to"* - What do you want it to? – acw1668 Nov 21 '22 at 13:38
  • FYI: You don't need both `from tkinter import *` and `import tkinter as tk` - stick with one. Most folks prefer `import tkinter as tk`, just remember to namespace your widgets appropriately; e.g. `tk.Entry` or `tk.Label`. In general, [star imports are a bad idea](https://www.geeksforgeeks.org/why-import-star-in-python-is-a-bad-idea/) since they pollute the namespace. – JRiggles Nov 21 '22 at 13:41
  • @acw1668 i want it to put a image instead of the usual gray/white background and i want it to put a rectangle inside the sub-window whrere i put the image as a background prior. It is wtitten as the text. – Emco Tec Nov 21 '22 at 14:31

0 Answers0