I'm using the tkinter GUI to call images and buttons to make a sorta "graphic novel" game (Probably not the most appropiate, but I don't have enough time to look for and use another library). Relevant code attached:
import random
import tkinter as tk
from tkinter import *
from PIL import Image, ImageTk
class juego:
def __init__(self):
self.root = tk.Tk()
self.nombreimagen = "room.jpg"
self.strparaA = " "
self.strparaB = " "
self.comparaA = " "
self.comparaB = " "
self.boton1 = tk.Button()
self.boton2 = tk.Button()
self.image = Image.open(self.nombreimagen)
self.estaes = ImageTk.PhotoImage(self.image)
self.pantalla = tk.Label()
def comenzar(self):
self.nombreimagen = "room.jpg"
self.root.geometry("960x720")
self.image = Image.open(self.nombreimagen)
self.estaes = ImageTk.PhotoImage(self.image)
self.pantalla = tk.Label(self.root, image=self.estaes)
self.pantalla.place(x=0, y=0)
self.boton1(self.root, text="A: Salir a la calle", command=self.A())
self.boton2(self.root, text="B: Quedarse en la casa", command=print("B"))
self.boton1.pack(side="bottom")
self.boton2.pack(side="bottom")
self.root.mainloop()
def A(self):
self.pantalla.forget()
self.image = Image.open("salir.png")
self.estaes = ImageTk.PhotoImage(self.image)
self.pantalla(self.root, image=self.estaes)
self.pantalla.place(x=0, y=0)
self.boton1(self.root, text="Funciona?")
self.boton2(self.root, text="Funciona!")
self.boton1.pack(side="bottom")
self.boton2.pack(side="bottom")
nombre = juego()
nombre.comenzar()
Where "comenzar" is the function for drawing the game's starting window. When I execute it I get the error "Label object is not callable" in line
self.pantalla(self.root, image=self.estaes)
self.pantalla should be the label defined in the ____init____