alejandroautalan / pygubu

A simple GUI builder for the python tkinter module
MIT License
2.01k stars 213 forks source link

My picture won't load #271

Closed Fefedu973 closed 1 year ago

Fefedu973 commented 1 year ago

idk why my picture dont render ?

!/usr/bin/python3

import tkinter as tk import tkinter.ttk as ttk from tkinter import * from PIL import ImageTk,Image

class AboutApp: def init(self, master=None):

build ui

    toplevel1 = tk.Tk() if master is None else tk.Toplevel(master)
    toplevel1.iconbitmap('settings.ico')
    toplevel1.configure(height=200, width=200)
    toplevel1.resizable(False, False)
    toplevel1.title("About Activity Condenser")
    frame2 = tk.Frame(toplevel1)
    frame2.configure(height=200, padx=50, pady=10, width=200)
    label1 = tk.Label(frame2)
    label1.configure(font="{Arial} 16 {bold}", text="Activity Condenser\n")
    label1.grid(column=0, padx="60 0", pady="0 15", row=0, sticky="w")
    button1 = tk.Button(frame2)
    button1.configure(cursor="hand2", text="Ok", width=12)
    button1.grid(column=0, pady="30 0", row=4)
    button1.configure(command=self.on_ok)
    separator3 = ttk.Separator(frame2)
    separator3.configure(orient="horizontal")
    separator3.grid(column=0, ipadx=120, pady="10 40", row=4)
    separator4 = ttk.Separator(frame2)
    separator4.configure(orient="horizontal")
    separator4.grid(column=0, ipadx=120, pady="0 40", row=2)
    label2 = ttk.Label(frame2)
    label2.configure(
        text="Activity condenser is an application that allows you \nto condense several discord activities into a single \nanimated one\n\nCopytight © 2022 Fefe_du_973\n\nThis program is free software: you can redistribute\nit and/or modify it under the terms of the GNU\nGeneral Public License as published by the Free\n Software Foundation, either version 3 of the \nLicense, or (at your option) any later version.\n\nThis program is distributed in the hope that \nit will be useful, but WITHOUT ANY WARRANTY;\n without even the implied warranty of \nMERCHANTABILITY or FITNESS FOR A \nPARTICULAR PURPOSE. See the \nGNU General Public License for more details.\nYou should have received a copy of the GNU \nGeneral Public License along with this program."
    )
    label2.grid(column=0, row=3)
    label4 = ttk.Label(frame2)
    label4.configure(font="{Arial} 12 {}", text="Version 1.0")
    label4.grid(column=0, padx="60 0", row=0, sticky="w")
    canvas1 = tk.Canvas(frame2)
    canvas1 = Canvas(width = 300, height = 300)  
    canvas1.pack()  
    img = ImageTk.PhotoImage(Image.open("icon2.png"))  
    canvas1.create_image(20, 20, anchor=NW, image=img) 
    frame2.pack(side="top")

   # Main widget
    self.mainwindow = toplevel1

def run(self):
    self.mainwindow.mainloop()

def on_ok(self):
    self.mainwindow.destroy()

if name == "main": app = AboutApp() app.run()

unknown.png

alejandroautalan commented 1 year ago

Hello @Fefedu973 thanks for trying pygubu.

The image is getting garbage collected by python. You have to maintain a reference to the image. Change the image line to:

self.img = img = ImageTk.PhotoImage(Image.open("icon2.png"))

Code generation is not aware of this cases yet. Let me know.

Regards Alejandro A

Fefedu973 commented 1 year ago

Tanks it works !!!!?

Fefedu973 commented 1 year ago

can i ask you another question ? i want to change text color with a funtion but it doesn't work image