Beginner / its my 1st time asking a question over here (.. over anywhere else also) so let me apologies in advance if any rules would'have not been followed

I'am doing an interface on raspbian/tkinter to work with Raspberry Pi touchscreen. (simple commands done when touching differents parts of the screen)

Question is, I have multiple windows with buttons inside, how to insert image in some of them buttons ?

Position of the windows are determinant for the application, so use of top level or all buttons in single window etc is no good option imo...and I dont understand class enough to use this tool< any help on this would be much appreciated

It is probably not ideal but I created 3 different window with 2 buttons in each (see picture) . using a single window to hold all buttons is not good as it is limited to the N/S/E/W positioning.

when you lunch the software you got this

for exemple I try to put image instead of text buttons for the button on the bottom right (he blank one) it shows error :

Traceback (most recent call last):
  File "/home/pi/test/StackExchangeQ/test fullscreen", line 50, in <module>
    b = Button(master, image=image, command=zone_x, height=16, width=10)
  File "/usr/lib/python3.5/tkinter/", line 2221, in __init__
    Widget.__init__(self, master, 'button', cnf, kw)
  File "/usr/lib/python3.5/tkinter/", line 2151, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist

with the code below ;

import tkinter as tk
from tkinter import *
import PIL
from PIL import ImageTk

def zone_a() :

def zone_b() :

def zone_c() :

def zone_d() :

def zone_x() :

#creation of 3 window
win1 = Tk()
win2 = Tk()
master = Tk()

# determine geometry and position of windows: win.geomtry(height,weight,x,y)
# x and y position from top left corner of the screen


#suppress windows toolbars

Button(win1, text="ZoneA", command=zone_a, height=16, width=45).pack()
Button(win1, text="ZoneB", command=zone_b, height=16, width=45).pack()
Button(win2, text="ZoneC", command=zone_c, height=16, width=45).pack()
Button(win2, text="ZoneD", command=zone_d, height=16, width=45).pack()

#Thoses 2 buttons that I would like to change into image buttons.
#Button(win3, text="Exit", command=quit, height=16, width=10).pack()
#Button(win3, text="", command=zone_x, height=16, width=10 ).pack()
image = ImageTk.PhotoImage(file="button_zone-x.png")

Button(win2, text="Exit", command=quit, height=16, width=10).pack()
b = Button(master, image=image, command=zone_x, height=16, width=10)
b.image = image


how can I get to the result I want with the positioning and knowledge constraints expressed before ?

  • This is a programming question which should be asked on StackOverflow. – Dmitry Grigoryev Sep 25 at 13:09

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.