[英]How to put an image on another image in python, using ImageTk?
我想將圖像放在另一個圖像的前面,然后在Tkinter中將此組合圖像用作按鈕的背景圖像。
我該怎么做?
我可以自由import Tkimage, Image
。
澄清:我要堅持這個 在這個中心 這樣的東西 將實現! (我想寫《 Candy Crush!》作為作業!)
只需使用photoshop或GIMP即可 。 我向您保證,與本質上讓Tkinter為您進行照片編輯相比,用這種方法將更加簡單和減少冗余(更不用說您在說什么了,這只是編碼時的錯誤做法)
無論如何,我想如果您真的想要,那將是可能的。 使用圖像功能(image =“ path \\ to \\ image.png”)創建一個tkinter按鈕,然后將其分配給.grid()。 對於第二個圖像,將其分配給相同的 .grid()協調器,同時確保覆蓋圖像是透明的。 這是一個非常籠統的示例,因為我得到的信息很少。
Button0 = tk.Button(self, compound="top", image=.\path\to\BackgroundImage.png, fg="black", command=lambda: "call your function here"
Button0.grid(row=1, column=1, padx=10, pady=10)
Button1 = tk.Button(self, compound="top", image=.\path\to\TransparentCandyImage.png, fg="black", command=lambda: "call your function here"
Button1.grid(row=1, column=1, padx=10, pady=10)
編輯:您還可以查找集成到GIMP中的Python /腳本(稱為“ Script-Fu's”)以執行批量照片編輯。 那里有很多可以做各種很酷的事情,但是我不知道有什么可以完全滿足您的需求的。 以下是一些看起來很有希望的快速搜索結果:
* http://www.gimp.org/tutorials/Basic_Batch/
* http://registry.gimp.org/taxonomy/term/176
* http://www.sandyscott.net/2013/08/04/batch-editing-with-gimp-script-fu/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.