Created
October 5, 2016 15:40
-
-
Save VieVie31/80f1d24f233f9336bcd7426a066270c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tkinter as tk | |
from comptage_sql import * | |
def format_row(t): | |
return "ID: {}, {}, {}-{}".format( | |
t[0], "HOMME" if not t[1] else "FEMME", | |
t[2], t[2] + 10) | |
def onselect(evt): | |
w = evt.widget | |
index = int(w.curselection()[0]) | |
value = w.get(index) | |
dlg = Dialog(app, "Supprimer cette personne ?", value) | |
print dlg.result | |
if dlg.result: | |
p_id = int(value.split(',')[0][4:]) | |
remove_id(p_id) | |
w.delete(index) | |
app.update_GUI() | |
class Dialog(tk.Toplevel): | |
def __init__(self, parent, title=None, txt=""): | |
tk.Toplevel.__init__(self, parent) | |
self.transient(parent) | |
if title: | |
self.title(title) | |
self.txt = txt | |
self.parent = parent | |
self.result = None | |
body = tk.Frame(self) | |
self.initial_focus = self.body(body) | |
body.pack(padx=5, pady=5) | |
self.buttonbox() | |
self.grab_set() | |
if not self.initial_focus: | |
self.initial_focus = self | |
self.protocol("WM_DELETE_WINDOW", self.cancel) | |
self.geometry("+%d+%d" % (parent.winfo_rootx()+50, | |
parent.winfo_rooty()+50)) | |
self.initial_focus.focus_set() | |
self.wait_window(self) | |
def body(self, master): | |
pass | |
def buttonbox(self): | |
box = tk.Frame(self) | |
lbl = tk.Label(box, text=self.txt) | |
lbl.pack() | |
w = tk.Button(box, text="OK", width=10, command=self.ok, default=tk.ACTIVE) | |
w.pack(side=tk.LEFT, padx=5, pady=5) | |
w = tk.Button(box, text="Cancel", width=10, command=self.cancel) | |
w.pack(side=tk.LEFT, padx=5, pady=5) | |
self.bind("<Return>", self.ok) | |
self.bind("<Escape>", self.cancel) | |
box.pack() | |
def ok(self, event=None): | |
self.result = 1 | |
if not self.validate(): | |
self.initial_focus.focus_set() | |
return | |
self.withdraw() | |
self.update_idletasks() | |
self.apply() | |
self.parent.focus_set() | |
self.destroy() | |
def cancel(self, event=None): | |
self.result = 0 | |
self.parent.focus_set() | |
self.destroy() | |
def validate(self): | |
self.result = 1 | |
return 1 | |
def apply(self): | |
pass | |
class ComptageApp(tk.Tk): | |
def __init__(self, parent): | |
tk.Tk.__init__(self, parent) | |
self.parent = parent | |
self.initialize() | |
def update_GUI(self): | |
self.lb.insert(0, format_row(get_latest_persons(1)[0])) | |
self.people_count.set("Il y a : {} personnes.".format(count_persons())) | |
def initialize(self): | |
self.grid() | |
self.b1 = tk.Button(self, | |
text="0-10", | |
fg="blue", | |
command=lambda : (insert_person(0, 0), | |
self.update_GUI())) | |
self.b2 = tk.Button(self, | |
text="0-10", | |
fg="red", | |
command=lambda : (insert_person(1, 0), | |
self.update_GUI())) | |
self.b3 = tk.Button(self, | |
text="11-20", | |
fg="blue", | |
command=lambda : (insert_person(0, 11), | |
self.update_GUI())) | |
self.b4 = tk.Button(self, | |
text="11-20", | |
fg="red", | |
command=lambda : (insert_person(1, 11), | |
self.update_GUI())) | |
self.b5 = tk.Button(self, | |
text="21-30", | |
fg="blue", | |
command=lambda : (insert_person(0, 21), | |
self.update_GUI())) | |
self.b6 = tk.Button(self, | |
text="21-30", | |
fg="red", | |
command=lambda : (insert_person(1, 21), | |
self.update_GUI())) | |
self.lb = tk.Listbox(self, fg="darkgreen") | |
self.lb.bind('<<ListboxSelect>>', onselect) | |
self.people_count = tk.StringVar() | |
self.lbl = tk.Label(self, textvariable=self.people_count) | |
self.people_count.set("Il y a : {} personnes.".format(count_persons())) | |
self.b1.pack({"side": "left"}) | |
self.b2.pack({"side": "right"}) | |
self.b3.pack({"side": "left"}) | |
self.b4.pack({"side": "right"}) | |
self.b5.pack({"side": "left"}) | |
self.b6.pack({"side": "right"}) | |
self.lb.pack({"side": "bottom"}) | |
self.lbl.pack({"side": "top"}) | |
if __name__ == "__main__": | |
app = ComptageApp(None) | |
app.title('Super application de comptage de la mort qui tue') | |
app.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment