commit 1d190af7ceda11615dee1def7d127a79075f74ba Author: barraux.a Date: Sat Feb 5 16:26:49 2022 +0100 premier commit diff --git a/main.py b/main.py new file mode 100644 index 0000000..5149b95 --- /dev/null +++ b/main.py @@ -0,0 +1,85 @@ +import tkinter + +class Terrain: + def __init__(self): + self.height = 15000//25 + self.width = 28000//25 + self.three_points = 6250//25 # rayon + self.middle_circle = 1800//25 # rayon + + +class Team: + def __init__(self): + self.players = ['arthur', 'jl', 'léandre', "louis", "alex"] + self.file = 'stat.txt' + self.posx, self.posy = 0,0 # coo de la dernière action + self.ac_player = 0 # dernier joueur + + + + + +class Gui: + def __init__(self, ): + self.terrain = Terrain() + self.team = Team() + self.list_button_menu = [] + self.win = tkinter.Tk() + self.canvas = tkinter.Canvas(self.win, width=self.terrain.width, height=self.terrain.height, background='#bbb') + + self.canvas.pack() + + # menu contextuel des actions + self.action = tkinter.Menu(self.win, tearoff=0) + self.action.add_command(label='marque', command=lambda: self.action_menu('marque')) + self.action.add_command(label='rate', command=lambda: self.action_menu('rate')) + + + # Menu contextuel des joueurs + self.menu = tkinter.Menu(self.win, tearoff = 0) + self.menu.add_command(label=self.team.players[0], command=lambda: self.show_sub_menu(self.team.players[0])) + self.menu.add_command(label=self.team.players[1], command=lambda: self.show_sub_menu(self.team.players[1])) + self.menu.add_command(label=self.team.players[2], command=lambda: self.show_sub_menu(self.team.players[2])) + self.menu.add_command(label=self.team.players[3], command=lambda: self.show_sub_menu(self.team.players[3])) + self.menu.add_command(label=self.team.players[4], command=lambda: self.show_sub_menu(self.team.players[4])) + + + + def context_menu(self, event): + self.team.posx, self.team.posy = event.x, event.y + self.coo = [event.x_root, event.y_root] + self.menu.tk_popup(event.x_root, event.y_root) + self.menu.grab_release() + + def show_sub_menu(self, player): + self.team.ac_player = player + self.action.tk_popup(self.coo[0], self.coo[1]) + self.action.grab_release() + + def action_menu(self, action): + if action == 'marque': + self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='green') + # with open('stat.txt', 'a') as f: + + else: + self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='red') + + def draw_terrain(self): + # ligne des 3 points + self.canvas.create_arc(-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=-180) + self.canvas.create_arc(self.terrain.width-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.width+self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=180) + + # ligne centrale + + self.canvas.create_line(self.terrain.width//2, 0, self.terrain.width//2, self.terrain.height, width=3) + + # cercle du milieu + self.canvas.create_oval(self.terrain.width//2 - self.terrain.middle_circle, self.terrain.height//2 - self.terrain.middle_circle, self.terrain.width//2 + self.terrain.middle_circle, self.terrain.height//2 + self.terrain.middle_circle, width=3) + + +gui = Gui() +gui.draw_terrain() + +gui.win.bind("", gui.context_menu) + +gui.win.mainloop() diff --git a/stat.txt b/stat.txt new file mode 100644 index 0000000..e69de29 diff --git a/test.py b/test.py new file mode 100644 index 0000000..5b80cd9 --- /dev/null +++ b/test.py @@ -0,0 +1,27 @@ +from tkinter import * + +class Window(Frame): + def __init__(self, master=None): + Frame.__init__(self, master) + self.master = master + + menu = Menu(self.master) + self.master.config(menu=menu) + + fileMenu = Menu(menu) + fileMenu.add_command(label="Item") + fileMenu.add_command(label="Exit", command=self.exitProgram) + menu.add_cascade(label="File", menu=fileMenu) + + editMenu = Menu(menu) + editMenu.add_command(label="Undo") + editMenu.add_command(label="Redo") + menu.add_cascade(label="Edit", menu=editMenu) + + def exitProgram(self): + exit() + +root = Tk() +app = Window(root) +root.wm_title("Tkinter window") +root.mainloop() \ No newline at end of file