1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
from Tkinter import *
from random import*
import tkMessageBox
fen= Tk()
fen.geometry("450x450+400+100")
fen.title("Bataille Navale")
def quitter():
fermer=tkMessageBox.askyesno(title="Quitter", message="Voulez vous vraiment quitter ?")
if fermer>0:
fen.destroy()
return
menu=Menu(fen)
option=Menu(menu, tearoff=0)
option.add_command(label="Nouvelle partie")
option.add_command(label="Quitter", command=quitter)
option.add_command(label="A propos de...")
menu.add_cascade(label="Options", menu=option)
fen.config(menu=menu)
def wm_resizable(self, width=None, height=None): #fonction permetant un redimensionnement de la fenetre
for ligne in range(5):
for colonne in range(5):
Button(fen, (ligne, colonne),width=5,height=7,borderwidth=3).grid(row=ligne, column=colonne)
Button(fen, text='A1', borderwidth=3, fg="red", bg="blue").grid(row=1, column=1)
Button(fen, text='A2', borderwidth=3, fg="red", bg="blue").grid(row=2, column=1)
Button(fen, text='A3', borderwidth=3, fg="red", bg="blue").grid(row=3, column=1)
Button(fen, text='A4', borderwidth=3, fg="red", bg="blue").grid(row=4, column=1)
Button(fen, text='A5', borderwidth=3, fg="red", bg="blue").grid(row=5, column=1)
Button(fen, text='B1', borderwidth=3, fg="red", bg="blue").grid(row=1, column=2)
Button(fen, text='B2', borderwidth=3, fg="red", bg="blue").grid(row=2, column=2)
Button(fen, text='B3', borderwidth=3, fg="red", bg="blue").grid(row=3, column=2)
Button(fen, text='B4', borderwidth=3, fg="red", bg="blue").grid(row=4, column=2)
Button(fen, text='B5', borderwidth=3, fg="red", bg="blue").grid(row=5, column=2)
Button(fen, text='C1', borderwidth=3, fg="red", bg="blue").grid(row=1, column=3)
Button(fen, text='C2', borderwidth=3, fg="red", bg="blue").grid(row=2, column=3)
Button(fen, text='C3', borderwidth=3, fg="red", bg="blue").grid(row=3, column=3)
Button(fen, text='C4', borderwidth=3, fg="red", bg="blue").grid(row=4, column=3)
Button(fen, text='C5', borderwidth=3, fg="red", bg="blue").grid(row=5, column=3)
Button(fen, text='D1', borderwidth=3, fg="red", bg="blue").grid(row=1, column=4)
Button(fen, text='D2', borderwidth=3, fg="red", bg="blue").grid(row=2, column=4)
Button(fen, text='D3', borderwidth=3, fg="red", bg="blue").grid(row=3, column=4)
Button(fen, text='D4', borderwidth=3, fg="red", bg="blue").grid(row=4, column=4)
Button(fen, text='D5', borderwidth=3, fg="red", bg="blue").grid(row=5, column=4)
Button(fen, text='E1', borderwidth=3, fg="red", bg="blue").grid(row=1, column=5)
Button(fen, text='E2', borderwidth=3, fg="red", bg="blue").grid(row=2, column=5)
Button(fen, text='E3', borderwidth=3, fg="red", bg="blue").grid(row=3, column=5)
Button(fen, text='E4', borderwidth=3, fg="red", bg="blue").grid(row=4, column=5)
Button(fen, text='E5', borderwidth=3, fg="red", bg="blue").grid(row=5, column=5)
#choix position
liste=["A1","A2","A3","A4","A5","B1","B2","B3","B4","B5","C1","C2","C3","C4","C5","D1","D2","D3","D4","D5","E1","E2","E3","E4","E5"]
position=choice (liste)
print(position)
fen.mainloop() |
Partager