2016-05-03 11 views
0

上層に行くように指定された写真は透明ですが、灰色で表示されます前記透明度の代わりに正方形を使用し、背景をカバーする。Python、tkinter、およびPILを使用して、背景(画像でもある)上に透明画像を重ねる方法

私はPythonでTkinterとPILを使ってピンボールゲームをコーディングしています。バックグラウンド上にゲームの要素(フリッパー、バンパーなど)を表示する必要があるため、私は立ち往生していますが、オーバーレイしようとすると、すでに持っている透明度ではなく、灰色の四角で表示されます。

これはコードです:

import sys 
from tkinter import * 
from PIL import Image, ImageTk 


#Secci�³n funciones 
def botones(): 
    juego_Nuevo_Boton = Button(menu_Principal, text = ("Juego nuevo"), command = juegoNuevo, font = ("Arial Black", 10), width = 20).place(x = 15, y = 125) 
    continuar_Juego_Boton = Button(menu_Principal, text = "Continuar juego", font = ("Arial Black", 10), width = 20) .place(x = 15, y = 160) 
    cerrar_El_Juego = Button(menu_Principal, text = "Cerrar el juego", command = menu_Principal.destroy, font = ("Arial Black", 10), width = 20).place(x = 15, y = 195) 

def juegoNuevo(): 
    ventana_Juego_Nuevo = Toplevel() 
    ventana_Juego_Nuevo.geometry("600x700") 
    ventana_Juego_Nuevo.title("Nueva partida") 
    imagen_Fondo_Juego_Nuevo = PhotoImage(file = "fondo_Juego.gif") 
    fondo_Juego_Nuevo = Label(ventana_Juego_Nuevo, image=imagen_Fondo_Juego_Nuevo) 
    fondo_Juego_Nuevo.place(x = 0, y = 0, relwidth = 1, relheight = 1) 
    fondo_Juego_Nuevo.image = imagen_Fondo_Juego_Nuevo 
    imagen_lanzador_Canal = PhotoImage(file = "LanzadorCanal.gif") 
    Lanzador_Canal = Label(ventana_Juego_Nuevo, image = imagen_lanzador_Canal) 
    Lanzador_Canal.place(x = 0, y = 0) 
    Lanzador_Canal.image = imagen_lanzador_Canal 
    ############################################ 
    #I ALSO TRIED THIS BUT IT SHOWS UP SOME KIND OF IMAGE EDITOR CALLED "IMAGE MAGIC", 
    #I don't need to edit the pictures, i just need them overlayed, so i can finish the game. 

    #fondo_Del_Juego = Image.open("fondo_Juego.png") 
    #lanzador_Canal = Image.open("LanzadorCanal.png") 
    #fondo_Del_Juego.paste(lanzador_Canal, (0, 0), lanzador_Canal) 
    #fondo_Del_Juego.show() 
    ############################################# 
    ventana_Juego_Nuevo.mainloop() 
#Crear pantalla y titulo 

menu_Principal = Tk() 
menu_Principal.title("Pinball - Proyecto : creado por Daniel Bonilla") 
menu_Principal.geometry("200x400") 
imagen_Fondo_Menu = PhotoImage(file = "MenuPrincipal.gif") 
fondo_Menu = Label(menu_Principal, image = imagen_Fondo_Menu) 
fondo_Menu.place(x = 0, y = 0, relwidth = 1, relheight = 1) 
botones() 

#Llamado a la ventana 
menu_Principal.mainloop() 

は "JuegoNuevo()" 関数に特別な注意を払って、問題がどこにあるか、があります。

ので、かなり多く、この絵は私の問題を要約:

enter image description here

春はすでに透明である*、それだけでそのように表示されません。

後で、私は他の要素や衝突などをすべて入れなければならないことを覚えておいてください。「イメージマジック」(上のコードを参照)はうまくいかないと思います。

*編集:既にPNGファイルの最初の回答に記載されているように試しましたが、問題はそのまま残ります。

答えて

0

gifの代わりにpngを使用すると、問題が解決されます。

+0

私はすでにPNG、GIF、JPG、ICOを使用していますが、これらのフォーマットでも同じことが起こります。 ')。 –

+0

私のpngファイルであなたのコードを試してみましたが、正しく動作します:D –

+0

私はそれを試してみましょう.PNGを含む前述のフォーマットにJPGの写真をすべて変換したからです。私は "自然に作られた" pngの写真で試してみます。 –

関連する問題