[英]Rotate a label with image in tkinter
我試圖用帶有tkinter的畫布上的圖像旋轉標簽。
我有三個需要旋轉的圖像(俯仰,滾動和偏航),它們最終會根據IMU傳感器輸出旋轉。
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(root, width=w, height=h)
cv.pack(side='top', fill='both', expand='yes')
cv.create_image(0, 0, image=bg_image, anchor='nw')
#add images
pitch = tk.PhotoImage(file="Pitch2.gif")
pitch_lbl = tk.Label(cv, image=pitch,bg="white")
pitch_lbl.image = pitch
pitch_lbl.place(x=60, y=180)
roll = tk.PhotoImage(file="Roll2.gif")
roll_lbl = tk.Label(cv, image=roll,bg="white")
roll_lbl.image = roll
roll_lbl.place(x=325, y=180)
yaw = tk.PhotoImage(file="Yaw2.gif")
yaw_lbl = tk.Label(cv, image=yaw,bg="white")
yaw_lbl.image = yaw
yaw_lbl.place(x=590, y=180)
root.mainloop()
如何通過tkinter旋轉圖像標簽?
如果您想簡單地旋轉90,180或翻轉,那么您可以使用PIL
進行transpose
。
有關詳細信息,請參閱此鏈接: 轉置 。
以下是重要的部分,以防萬一將來制動鏈接:
Image.transpose(方法)移調圖像(以90度步進翻轉或旋轉)
參數:method - 以下之一:
返回:返回此圖像的翻轉或旋轉副本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.