-2
I’m training POO in a personal project that I’m developing in showing a window called by a button that shows "samples" of text from a language, showing a flag and text from that language. The problem is that the text appears, however, the image I want to appear in the window is not shown, although the path is correct relative to the file main.py
. In Pycharm, when you place your mouse on a path relative to a file that is image correctly it shows a pop-up with a preview of the image. I don’t know if I should make a reference from the position of the file ```main.pyou
commanding_init_.py```. It is structured in this way:
Examples
main.py
from uteis.comandos_botao import *
from tkinter import *
import tkinter.ttk as ttk
from ttkthemes import ThemedStyle
root = Tk()
style_alt = ThemedStyle(root)
style_alt.set_theme('breeze')
botao = ttk.Button(root, text="Hindi", command=bt_hindi)
botao.grid(row=0, column=0)
root.mainloop()
useful __init__.py
from tkinter import *
from uteis.textos import *
class JanelaIdioma():
def __init__(self, idioma, texto, bandeira):
self.idioma = idioma
self.texto = texto
self.bandeira = bandeira
def criar_janela(self):
if self.idioma == "Hindi":
self.texto = hindi
root_hindi = Toplevel()
bandeira = Label(root_hindi, image=self.bandeira)
bandeira.grid(row=0, column=0)
letreiro_hindi = Label(root_hindi, text=self.texto, font=("Arial", 36, "bold"))
letreiro_hindi.grid(row=1, column=0)
command _init_.py
from uteis import *
from uteis.textos import *
def bt_hindi():
bandeira_hindi = PhotoImage(file='img/india.png')
janela = JanelaIdioma("hindi", hindi, bandeira_hindi).criar_janela()
texts __init__.py
hindi = "ऐसा कोई नहीं है जो खुद दर्द को प्यार करता हो, जो ऐसा करने के पीछे हो और चाहता हो, बस क्योकि यह दर्द होता है..."
I know it’s a lot of code and in case you’re confused, the entire project is on Github around here.
What is the result for
PhotoImage(file='../img/india.png')
andPhotoImage(file='../../img/india.png')
?– Paulo Marques
@Paulomarques 1-
_tkinter.TclError: couldn't open "../img/india.png": no such file or directory
2-_tkinter.TclError: couldn't open "../../img/india.png": no such file or directory
. The complete error exceeds the maximum number of characters, so I put in the image here.– Lucas Ribeiro