0

I am fairly new to python programming, and I would like to create a program which has a background image of some dials, with some images on top which will be rotated depending on the output from some IMU sensors.

So far I have added a background, and have create a label with a photo using tkinter. However the shows up with a grey background (the original file has a transparent background).

import tkinter as tk
from tkinter import PhotoImage
from PIL import Image

root = tk.Tk()
root.title('Pitch/Roll/Yaw Simulator')

# pick image file
fname = "PRY_Diag_Dials.png"
bg_image = tk.PhotoImage(file=fname)

# get the width and height of the image
w = bg_image.width()
h = bg_image.height()

# size the window so the image will fill it
root.geometry("%dx%d+50+30" % (w, h))
cv = tk.Canvas(width=w, height=h)
cv.pack(side='top', fill='both', expand='yes')
cv.create_image(0, 0, image=bg_image, anchor='nw')

# add canvas text
cv.create_text(15, 20, text="Pitch/Roll/Yaw Simulator", fill="white", anchor='nw')

# add button widgets
btn1 = tk.Button(cv, text="Initialise")
btn1.pack(side='left', padx=10, pady=5, anchor='sw')
btn2 = tk.Button(cv, text="Quit", command=root.destroy)
btn2.pack(side='left', padx=10, pady=5, anchor='sw')

#add image labels
pitch = tk.PhotoImage(file="Pitch.gif")
w1 = tk.Label(cv, image=pitch).pack()

root.mainloop()

Is there a way to get a transparent background on the image label, so I can overlay it onto the background? And is tkinter the best thing to use if I'd like to rotate the images according to the sensor outputs?

Nicole C
  • 3
  • 5

0 Answers0