Browse Source

window fonctionnelle

master
parent
commit
3c29d7d4b4
  1. BIN
      util/.window.py.swp
  2. BIN
      util/50.png
  3. 26
      util/window.py

BIN
util/.window.py.swp

Binary file not shown.

BIN
util/50.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 463 B

26
util/window.py

@ -1,4 +1,4 @@
from tkinter import Tk, Label, Button, PhotoImage, Canvas, NW from tkinter import Tk, Label, Button, StringVar
from PIL import Image, ImageTk from PIL import Image, ImageTk
class Window(Tk): class Window(Tk):
@ -19,17 +19,25 @@ class Window(Tk):
self.c2 = None self.c2 = None
def build_window(self): def build_window(self):
"""Ajoute les composants de base à la fenêtre"""
self.title = Label(text="Bataille", font=("Courrier", 32)) self.title = Label(text="Bataille", font=("Courrier", 32))
self.title.grid(row=1, column=1) self.title.grid(row=1, column=1)
self.button = Button(self, text="Jouer") #, command=)
self.button = Button(self, text="Jouer", command=self.show_cards)
self.button.grid(row=4, column=1)
#.set() pour changer le texte
self.text_content = StringVar()
self.text = Label(self, textvariable=self.text_content)
self.text.grid(row=3, column=1)
def show_cards(self): def show_cards(self):
"""Affiche les dernières cartes jouées par les deux joueurs"""
if self.c1 is not None: if self.c1 is not None:
self.c1.destroy() self.c1.destroy()
if self.c2 is not None: if self.c2 is not None:
self.c2.destroy() self.c2.destroy()
#self.c1 = Label(text=self.p1.derniere_carte, font=("Courrier", 48))
#self.c2 = Label(text=self.p2.derniere_carte, font=("Courrier", 48))
img1 = ImageTk.PhotoImage(card_to_image(self.p1.derniere_carte)) img1 = ImageTk.PhotoImage(card_to_image(self.p1.derniere_carte))
self.c1 = Label(self, image=img1) self.c1 = Label(self, image=img1)
self.c1.photo = img1 self.c1.photo = img1
@ -37,17 +45,13 @@ class Window(Tk):
img2 = ImageTk.PhotoImage(card_to_image(self.p2.derniere_carte)) img2 = ImageTk.PhotoImage(card_to_image(self.p2.derniere_carte))
self.c2 = Label(image=img2) self.c2 = Label(image=img2)
self.c2.photo = img2 self.c2.photo = img2
self.c1.grid(row=2, column=0) self.c1.grid(row=2, column=0)
self.c2.grid(row=2, column=2) self.c2.grid(row=2, column=2)
def card_to_image(card): def card_to_image(card):
card_names = list(range(56-card.valeur*4, 52-card.valeur*4 , -1)) """Lie la valeur et couleur de la carte à son image"""
card_names = list(range(56-(card.valeur-1)*4, 52-(card.valeur-1)*4 , -1))
image = Image.open("./img/"+str(card_names[card.couleur])+".png") image = Image.open("./img/"+str(card_names[card.couleur])+".png")
print(str(card_names[card.couleur])+".png")
return image return image
if __name__ == "__main__":
card_to_image(Carte(2, 4))
#app = Window(None, None)
#app.show_cards()
#app.mainloop()

Loading…
Cancel
Save