-1

I wanted to make my app look more beautiful and it's harder than I though! Now I had an app with mainly 2 buttons and date-time label on top. Buttons are just with text, but I want to use pictures on them. That's my code now:

def showMainMenu():
    global cardNumber, allowToGPIO
    cardNumber = "" #Reset cardNumber global value
    allowToGPIO = True
    clear()
    showNewTime()
    watchDog.awake()
    GuestTestButton = Button(canvas, text="GUEST TEST", width=buttonwidth, height=buttonheight, compound = TKinter.CENTER, command = guestTest)
    GuestTestButton.config(font=("Mojave-Regular.ttf", 24))
    #GuestTestButton.pack()
    GuestTestButton.place(x=90, y=100)
    AddEmployeeButton = Button(canvas, text="ADD NEW USER", width=buttonwidth, height=buttonheight, compound = TKinter.CENTER, command = addEmployee)
    AddEmployeeButton.config(font=("Mojave-Regular.ttf", 24))
    #AddEmployeeButton.pack()
    AddEmployeeButton.place(x=90, y=270)

And for now, it works. But when I tried to make them more colorful (just use image instead of text), button shows up without anything on it. Is it even possible to make things like that in TKinter? Everything I do is on canvas:

app = TKinter.Tk()
canvas = TKinter.Canvas()

I tried to do this that way:

GuestImage = TKinter.PhotoImage(file="guest.gif")
GuestTestButton = Button(canvas, text="GUEST TEST", width=buttonwidth, height=buttonheight, compound = TKinter.CENTER, command = guestTest)
GuestTestButton.config(image=GuestImage, font=("Mojave-Regular.ttf", 24))
GuestTestButton.place(x=90, y=100)

But as I said, it's not working properly :D Thanks in advance for any help!

MateoSkyline
  • 309
  • 1
  • 5
  • 17
  • Possible duplicate of [How to add an Image to a widget](https://stackoverflow.com/questions/37515847/how-to-add-an-image-to-a-widget-why-is-the-image-not-displayed) – Miraj50 Dec 07 '18 at 07:40

1 Answers1

0

I got it now, my images shows up but it dissapears after miliseconds, now I made the GuestImage and AddEmployeeImage as global variables and it works perfectly!

MateoSkyline
  • 309
  • 1
  • 5
  • 17