Aug-03-2018, 09:25 AM
(This post was last modified: Aug-03-2018, 09:35 AM by Axel_Erfurt.)
I've made a test, saved your script in /tmp, copied an image to tmp (named it Hydrisgrande.png)
and it works from my IDE, but not from Terminal.
You forgot raiz.mainloop() at the end.
use
and it works from my IDE, but not from Terminal.
You forgot raiz.mainloop() at the end.
import tkinter from tkinter import * import os raiz=tkinter.Tk() raiz.title("Ver png") raiz.config(bg="White") # medida ventana w = raiz.winfo_screenwidth() h = raiz.winfo_screenheight() raiz.geometry("%dx%d+0+0" % (w, h)) # Bloqueo cambio tamaño pantalla raiz.resizable(width=False, height=False) directorio=os.path.dirname(__file__) print(w,h,directorio) Imagenfondo0=PhotoImage(file=directorio+"/Hydrisgrande.png") canvas=tkinter.Canvas(raiz,width=w,height=h,bg="white") canvas.place(x=1,y=1) image = canvas.create_image(1, 1, anchor=NW, image=Imagenfondo0) raiz.mainloop()in Terminal, this works for me
import tkinter from tkinter import * import os raiz=tkinter.Tk() raiz.title("Ver png") raiz.config(bg="White") # medida ventana w = raiz.winfo_screenwidth() h = raiz.winfo_screenheight() raiz.geometry("%dx%d+0+0" % (w, h)) # Bloqueo cambio tamaño pantalla raiz.resizable(width=False, height=False) directorio=os.path.dirname(__file__) print(w,h,directorio) picFile = "./Hydrisgrande.png" Imagenfondo0=PhotoImage(file=picFile) canvas=tkinter.Canvas(raiz,width=w,height=h,bg="white") canvas.place(x=1,y=1) image = canvas.create_image(1, 1, anchor=NW, image=Imagenfondo0) raiz.mainloop()
use
directorio=os.path.dirname(os.path.abspath(__file__))that works for me in both(IDE and Terminal)