Hi everyone,
I am trying to build application with Tkinter like a wizard, i'll use background image for application, and put some text and image to application window. But i couldn't do that.

When I use background with that code, text labels background color is blocking background view. Is there a way to create transparent texts with Tkinter.Label?

# use a Tkinter label as a panel/frame with a background image
# (note that Tkinter reads only GIF and PGM/PPM images)
import Tkinter as tk
root = tk.Tk()
root.title('background image')
# pick a .gif image file you have in the working directory
image1 = tk.PhotoImage(file="back1.gif")
w = image1.width()
h = image1.height()
root.geometry("%dx%d+0+0" % (w, h))
# tk.Frame has no image argument
# so use a label as a panel/frame
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
button2 = tk.Button(panel1, text='button2')
text1=tk.Label(panel1, text="Welcome to my app")
# save the panel's image from 'garbage collection'
panel1.image = image1
# start the event loop

And when I use canvas to that, text Labels work but I can get buttons to right positions.

import Tkinter as tk
root = tk.Tk()
c = tk.Canvas(width=640, height=480)
# the image
image = tk.PhotoImage(file="back1.gif")
c.create_image(0, 0, image=image)
# and now the text at coordinates (50, 50)
c.create_text(50, 50, text="whatever", fill="blue")

I am also using bind functions to show a mouseover and out text when cursor is on the buttons.
I prefer to use first code but I can't handle with text Labels

Recommended Answers

All 3 Replies

In order to make added text transparent you have to use the canvas approach. I left a working example here:

Thank you but i can't manage page changing for wizard.
I've created main screen with canvas successfully.
Then created buttons for other pages (for example; Wizard1, Wizard2, About, Exit)
then defined a function for each of them to navigate their own pages.
For example, when user clicks to about button, about information must be shown on the same window (it won't open new window or message box)
to do that i've written about button's function:

def about():
   #To delete first canvas
   #to create new canvas for about screen
    temscr = Canvas(width = 640, height = 480, bg = '#FFFFFF')
  #to give another background for about screen
    tembgop = Image.open("gui/tembg")
    temscr.create_image(0, 0, image = tembg, anchor = NW)
   #and finally packed it   
    temscr.pack(expand = YES, fill = BOTH)

but it doesn't work. Help me please to solve this problem.

OK, I can solve it
I've used place command instead of pack.
And cleaned canvas and used place_forget() to remove buttons when page changes

def erasecanvas():

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.