I'm writing a code about an image processor in Python. I want to open a window with some tools for image processing, to open the image I'm using the function filedialog.askopenfile
from tkinter.
I created a openImage()
function that asks the file path to the user, then displays the image with a menubar and some frames but every time that I run the program the filedialog.askopenfile
function runs without invoking it, and I don't know hot to fix it.
I need help because I'm having this problem since a couple of hours :(
Here is my code:
import tkinter as tk
from tkinter import filedialog
from tkinter.ttk import Label
import cv2
from PIL import Image, ImageTk
import webbrowser
def openImage():
fileLocation = filedialog.askopenfile(initialdir='/', title='Selecciona Un Archivo',
filetypes=(('png files', '*.png'), ('all files', '*.')))
global image
image = cv2.imread(fileLocation)
cv2.waitKey(0)
cv2.destroyAllWindows()
class Main(tk.Tk):
def __init__(self):
super().__init__()
self.title('Programa de Manipulación de Imagenes de JMMS')
self.geometry('600x600')
self.iconbitmap('tools/triforce.ico')
menu = tk.Menu(self)
filemenu = tk.Menu(menu, tearoff=0)
filemenu.add_command(label="Abrir Imagen", command=openImage())
filemenu.add_command(label="Guardar Imagen", command=None)
filemenu.add_separator()
filemenu.add_command(label="Salir", command=self.quit)
menu.add_cascade(label="Archivo", menu=filemenu)
toolsmenu = tk.Menu(menu, tearoff=0)
toolsmenu.add_command(label="Zoom", command=None)
menu.add_cascade(label="Herramientas", menu=toolsmenu)
helpmenu = tk.Menu(menu, tearoff=0)
helpmenu.add_command(label="Contacto", command=None)
menu.add_cascade(label="Ayuda", menu=helpmenu)
self.config(menu=menu)
toolsFrame = tk.Frame(self, width=50, height=600, background='white')
toolsFrame.grid(row=1, column=1)
frame = tk.Frame(self, width=500, height=550, background='gray')
frame.grid(row=1, column=2)
frame3 = tk.Frame(self, width=50, height=600, background='white')
frame3.grid(row=1, column=3)
if __name__ == '__main__':
main = Main()
main.mainloop()