def __init__(self,toplevel,player_dic,attribut_dic,inventory_dic,function=lambda :None,x_relative=0,y_relative=0): if toplevel: self.inventory_window = Toplevel() self.inventory_window.wm_overrideredirect(1) self.inventory_window.wm_geometry("+%d+%d" % (x_relative,y_relative)) self.inventory_window.focus_force() else: self.inventory_window = Tk() self.inventory_window.title("Inventory") self.inventory_window.resizable(False,False) self.inventory_window.iconbitmap("img/icone.ico") self.inventory_window.option_add('*Font','Constantia 12') #self.inventory_window.option_add('*Button.activebackground','darkgray') #self.inventory_window.option_add('*Button.activeforeground','darkgray') #self.inventory_window.option_add('*Button.relief','groove') #self.inventory_window.option_add('*Button.overRelief','ridge') self.inventory_window.option_add('*justify','left') self.inventory_window.option_add('*bg','lightgray') self.inventory_window.option_add('*compound','left') self.frame = Frame(self.inventory_window,height=1,width=1) self.frame.pack() self.inventory_canvas = Canvas(self.frame) self.inventory_canvas.pack(fill=BOTH,expand=True,padx=20,pady=20) self.player_dic = player_dic self.attribut_dic = attribut_dic self.inventory_dic = inventory_dic self.baseimg_dic = dictionnaires.dictionnaires_vierge(loadimg=True) self.create_imgdic() self.current_page = 1 self.number_of_page = self.func_number_of_page() self.playerimg = PhotoImage(file=self.player_dic['image']) self.function = function self.generate_page(self.current_page) self.inventory_window.deiconify() self.inventory_window.mainloop()
def show(self, player_dic, attribut_dic, function=lambda: None, x_relative=0, y_relative=0): if self.attribut_window: return self.function = function if type(self.widget) == str: if self.toplevel: self.attribut_window = Toplevel() self.attribut_window.wm_overrideredirect(1) self.attribut_window.wm_geometry("+%d+%d" % (x_relative, y_relative)) self.attribut_window.focus_force() else: self.attribut_window = Tk() else: x, y, cx, cy = self.widget.bbox("insert") x = x + self.widget.winfo_rootx() + 12 y = y + cy + self.widget.winfo_rooty() + 40 self.attribut_window = Toplevel(self.widget) self.attribut_window.wm_overrideredirect(True) self.attribut_window.wm_geometry("+%d+%d" % (x, y)) self.attribut_window.title("Attributs") self.attribut_window.resizable(False, False) self.attribut_window.iconbitmap("img/icone.ico") self.attribut_window.option_add('*Font', 'Constantia 12') #self.attribut_window.option_add('*Button.activebackground','darkgray') #self.attribut_window.option_add('*Button.activeforeground','darkgray') #self.attribut_window.option_add('*Button.relief','groove') #self.attribut_window.option_add('*Button.overRelief','ridge') self.attribut_window.option_add('*justify', 'left') self.attribut_window.option_add('*bg', 'lightgray') self.attribut_window.option_add('*compound', 'left') self.attribut_canvas = Canvas(self.attribut_window) self.attribut_canvas.pack(fill=BOTH, expand=True, padx=20, pady=20) self.player_dic = player_dic self.attribut_dic = attribut_dic self.img_dic = dictionnaires.dictionnaires_vierge(loadimg=True) # Statistiques du joueurs k = 5 # nombre de lignes utilisées avant les attributs playerimage = PhotoImage(file=self.player_dic['image']) name_label = Label(self.attribut_canvas, text=self.player_dic['name'], font="Constantia 13 bold", image=playerimage) name_label.grid(row=0, column=0, sticky=W, columnspan=1) level_label = Label(self.attribut_canvas, text=str(self.player_dic['level']), font="Constantia 13 bold", image=self.img_dic['starnoir']) level_label.grid(row=0, column=0, columnspan=10) xp_label = Label(self.attribut_canvas, text=str(self.player_dic['current_xp']) + '/' + str(self.player_dic['max_xp']), font='Constantia 13 bold', image=self.img_dic['xpnoir']) xp_label.grid(row=0, column=2, columnspan=1, sticky=E) Frame(self.attribut_canvas, height=20).grid(row=1) txt_point_label = Label(self.attribut_canvas, text='Disponible : ', font='Constantia 13 bold', image=self.img_dic['star']) txt_point_label.grid(row=1, column=0, columnspan=10) self.point_label = Label(self.attribut_canvas, text=str(self.player_dic['attribut_point']), font='Constantia 13 bold') self.point_label.grid(row=1, column=1, columnspan=2) # Ecriture de tous les boutons # On ajoute 'name' pour pouvoir les identifier en cliquant dessus if player_dic['attribut_point'] > 0: plus_state = 'normal' minus_state = 'disabled' else: plus_state = 'disabled' minus_state = 'disabled' attribut_name_list = list(self.attribut_dic.keys())[:6] self.widget_list = [] imglist = [] for i in range(len(attribut_name_list)): attribut_name = str(attribut_name_list[i]) attribut_value = int(self.attribut_dic[attribut_name]['level']) color = str(self.attribut_dic[attribut_name]['color']) imglist.append( PhotoImage(file=self.attribut_dic[attribut_name]['image'])) l1 = Label(self.attribut_canvas, text=" " + attribut_name, fg=color, font="Constantia 16 bold", image=imglist[i]) l1.grid(row=i + k, column=0, padx=20, pady=5, sticky=W) b1 = Button(self.attribut_canvas, text="+", name=f'1|{i}', state=plus_state, font='Constantia 15 bold', fg='green') b1.grid(row=i + k, column=1, padx=2) b1.bind('<Button-1>', self.plus) b2 = Button(self.attribut_canvas, text="-", name=f'2|{i}', state=minus_state, font='Constantia 15 bold', fg='red') b2.grid(row=i + k, column=3, padx=2) b2.bind('<Button-1>', self.minus) l2 = Label(self.attribut_canvas, text=attribut_value, font='Constantia 16', width=3) l2.grid(row=i + k, column=2) self.widget_list.append({ 'attribut_name': l1, 'button1': b1, 'button2': b2, 'attribut_value': l2, 'point_spent': 0, 'button1_state': plus_state, 'button2_state': minus_state }) if type(self.widget) == str: ctt.CreateToolTip( l1, self.attribut_dic[attribut_name]['description']) if type(self.widget) == str: # Séparateur suivi du bouton 'Confirmer' Frame(self.attribut_canvas, height=20, width=400).grid(row=i + k + 1) self.confirmbutton = Button(self.attribut_canvas, text="Confirmer", command=self.confirm) self.confirmbutton.grid(row=i + k + 2, column=0, columnspan=10) self.attribut_window.mainloop()
def __init__(self, toplevel, player_dic, attribut_dic, function=lambda: None, x_relative=0, y_relative=0): self.function = function if toplevel: self.level_window = Toplevel() self.level_window.wm_overrideredirect(1) self.level_window.wm_geometry('+%d+%d' % (x_relative, y_relative)) self.level_window.focus_force() else: self.level_window = Tk() self.level_window.title("Pas assez d'expérience...") self.level_window.resizable(False, False) self.level_window.iconbitmap("img/icone.ico") self.level_window.option_add('*Font', 'Constantia 12') self.level_window.option_add('*Button.activebackground', 'darkgray') self.level_window.option_add('*Button.activeforeground', 'darkgray') self.level_window.option_add('*Button.relief', 'groove') self.level_window.option_add('*Button.overRelief', 'ridge') self.level_window.option_add('*justify', 'left') self.level_window.option_add('*bg', 'lightgray') self.level_window.option_add('*compound', 'left') self.level_canvas = Canvas(self.level_window) self.level_canvas.pack(fill=BOTH, expand=True, padx=20, pady=20) self.player_dic = player_dic self.attribut_dic = attribut_dic self.img_dic = dictionnaires.dictionnaires_vierge(loadimg=True) self.newlevel = 0 self.newattributpoint = 0 self.newspellpoint = 0 playerimg = PhotoImage(file=self.player_dic['image']) name_label = Label(self.level_canvas, text=self.player_dic['name'], font="Constantia 13 bold", image=playerimg) name_label.grid(row=0, column=0, sticky=W, columnspan=10) self.level_label = Label(self.level_canvas, text=str(self.player_dic['level']), font="Constantia 13 bold", image=self.img_dic['starnoir']) self.level_label.grid(row=0, column=0, columnspan=10) self.xp_label = Label(self.level_canvas, text=str(self.player_dic['current_xp']) + '/' + str(self.player_dic['max_xp']), font='Constantia 13 bold', image=self.img_dic['xpnoir']) self.xp_label.grid(row=0, column=0, columnspan=100, sticky=E) Frame(self.level_canvas, height=20).grid(row=1) if int(self.player_dic['attribut_point']) > 1: s = 's' else: s = '' txt = f"Attribut point{s} : {str(self.player_dic['attribut_point'])}" self.txt_point_label1 = Label(self.level_canvas, text=txt, font='Constantia 13 bold', image=self.img_dic['star']) self.txt_point_label1.grid(row=1, column=0, columnspan=10) if int(self.player_dic['spell_point']) > 1: s = 's' else: s = '' txt = f"Spell point{s} : {str(self.player_dic['spell_point'])}" self.txt_point_label2 = Label(self.level_canvas, text=txt, font='Constantia 13 bold', image=self.img_dic['star']) self.txt_point_label2.grid(row=2, column=0, columnspan=10) # Séparateur Frame(self.level_canvas, height=10, width=400).grid(row=3) self.txt_levelup1 = Label(self.level_canvas, text=f'', font='Constantia 13 bold') self.txt_levelup1.grid(row=4, column=0, columnspan=10) self.txt_levelup2 = Label( self.level_canvas, text=f"Vous n'avez pas assez d'expérience pour level up...", font='Constantia 13 bold') self.txt_levelup2.grid(row=5, column=0, columnspan=10) self.txt_levelup3 = Label(self.level_canvas, text=f'', font='Constantia 13 bold') self.txt_levelup3.grid(row=6, column=0, columnspan=10) # Séparateur Frame(self.level_canvas, height=20, width=400).grid(row=7) self.confirmbutton = Button(self.level_canvas, text="Confirmer", command=self.confirm) self.confirmbutton.grid(row=10, column=0, columnspan=10) self.checkforlevelup() self.level_window.deiconify() self.level_window.mainloop()
def show(self, player_dic, spell_dic, function=lambda: None, x_relative=0, y_relative=0): if self.spell_window: return self.function = function if type(self.widget) == str: if self.toplevel: self.spell_window = Toplevel() self.spell_window.wm_overrideredirect(1) self.spell_window.wm_geometry("+%d+%d" % (x_relative, y_relative)) self.spell_window.focus_force() else: self.spell_window = Tk() self.bold_font13 = "Constantia 13 bold" self.bold_font16 = "Constantia 16 bold" self.classic_font16 = "Constantia 16" self.underline_font12 = "Constantia 12 bold underline" self.bold_font12 = "Constantia 12 bold" self.classic_font12 = "Constantia 12" else: x, y, cx, cy = self.widget.bbox("insert") x = x + self.widget.winfo_rootx() + 12 y = y + cy + self.widget.winfo_rooty() + 40 self.spell_window = Toplevel(self.widget) self.spell_window.wm_overrideredirect(1) self.spell_window.wm_geometry("+%d+%d" % (x, y)) self.bold_font13 = "Constantia 8 bold" self.bold_font16 = "Constantia 9 bold" self.classic_font16 = "Constantia 9" self.underline_font12 = "Constantia 8 bold underline" self.bold_font12 = "Constantia 6 bold" self.classic_font12 = "Constantia 6" self.spell_window.title("Spells") self.spell_window.resizable(False, False) self.spell_window.iconbitmap("img/icone.ico") self.spell_window.option_add('*font', 'Constantia 12') self.spell_window.option_add('*Button.activebackground', 'darkgray') self.spell_window.option_add('*Button.activeforeground', 'darkgray') self.spell_window.option_add('*Button.relief', 'groove') self.spell_window.option_add('*Button.overRelief', 'ridge') self.spell_window.option_add('*justify', 'left') self.spell_window.option_add('*bg', 'lightgray') self.spell_window.option_add('*compound', 'left') self.spell_canvas = Canvas(self.spell_window) self.spell_canvas.pack(fill=BOTH, expand=True, padx=20, pady=20) self.player_dic = player_dic self.spell_dic = spell_dic self.img_dic = dictionnaires.dictionnaires_vierge(loadimg=True) self.bind_state = (-1, 'off') self.spell_window.bind_all('<Key>', self.listen) self.liste_num = ['&', 'é', '"', "'", "(", "-", "è", "_", "ç", "à"] self.next_label_bind = 0 # Statistiques du joueurs k = 5 # nombre de lignes utilisées avant les spells playerimg = PhotoImage(file=self.player_dic['image']) name_label = Label(self.spell_canvas, text=self.player_dic['name'], font=self.bold_font13, image=playerimg) name_label.grid(row=0, column=0, sticky=W, columnspan=10) level_label = Label(self.spell_canvas, text=str(self.player_dic['level']), font=self.bold_font13, image=self.img_dic['starnoir']) level_label.grid(row=0, column=0, columnspan=10) xp_label = Label(self.spell_canvas, text=str(self.player_dic['current_xp']) + '/' + str(self.player_dic['max_xp']), font=self.bold_font13, image=self.img_dic['xpnoir']) xp_label.grid(row=0, column=0, columnspan=100, sticky=E) Frame(self.spell_canvas, height=20).grid(row=1) txt_point_label = Label(self.spell_canvas, text='Disponible : ', font=self.bold_font13, image=self.img_dic['star']) if type(self.widget) == str: txt_point_label.grid(row=1, column=0, columnspan=10) else: txt_point_label.grid(row=1, column=0) self.point_label = Label(self.spell_canvas, text=str(self.player_dic['spell_point']), font=self.bold_font13) self.point_label.grid(row=1, column=1, columnspan=10, sticky=W) if type(self.widget) == str: self.point_label.grid(row=1, column=1, columnspan=10, sticky=W) else: self.point_label.grid(row=1, column=1) # Ecriture de tous les boutons # On ajoute 'name' pour pouvoir les identifier en cliquant dessus if player_dic['spell_point'] > 0: plus_state = 'normal' minus_state = 'disabled' else: plus_state = 'disabled' minus_state = 'disabled' self.widget_list = [] total_number_of_spells = self.spell_dic['total_number_of_spells'] imglist = [] for i in range(total_number_of_spells): spell_number = f'spell{i+1}' spell_name = str(self.spell_dic[f'spell{i+1}']['name']) spell_value = int(self.spell_dic[f'spell{i+1}']['level']) spell_bind = str(self.spell_dic[f'spell{i+1}']['bind']) color = str(self.spell_dic[f'spell{i+1}']['color']) if type(self.widget) == str: imglist.append( PhotoImage(file=self.spell_dic[f'spell{i+1}']['image'])) else: imglist.append(self.img_dic['vide']) l1 = Label(self.spell_canvas, name=f'0|{i}', text=" " + spell_name, fg=color, font=self.classic_font12, image=imglist[i]) l1.grid(row=i + k, column=0, padx=20, pady=1, sticky=W) l1.bind('<Button-1>', self.bind_label) b1 = Button(self.spell_canvas, text="+", name=f'1|{i}', state=plus_state, font=self.bold_font16, fg='green') b1.grid(row=i + k, column=1, padx=2) b1.bind('<Button-1>', self.plus) b2 = Button(self.spell_canvas, text="-", name=f'2|{i}', state=minus_state, font=self.bold_font16, fg='red') b2.grid(row=i + k, column=3, padx=2) b2.bind('<Button-1>', self.minus) l2 = Label(self.spell_canvas, text=spell_value, font=self.classic_font16, width=3) l2.grid(row=i + k, column=2) b3 = Button(self.spell_canvas, text=f'< {spell_bind} >', name=f'3|{i}', font=self.bold_font12, fg='black') b3.grid(row=i + k, column=4, padx=10) b3.bind('<Button-1>', self.bind_button) self.widget_list.append({ 'spell_name': l1, 'button1': b1, 'button2': b2, 'button3': b3, 'spell_value': l2, 'point_spent': 0, 'button1_state': plus_state, 'button2_state': minus_state }) if type(self.widget) == str: ctt.CreateToolTip(l1, self.spell_dic[spell_number]['description']) if type(self.widget) == str: # Séparateur suivi du bouton 'Confirmer' Frame(self.spell_canvas, height=10, width=400).grid(row=i + k + 1) self.confirmbutton = Button(self.spell_canvas, text="Confirmer", command=self.confirm) self.confirmbutton.grid(row=i + k + 2, column=0, columnspan=10) self.underline_activebind() try: self.spell_window.mainloop() except: pass
def Tooltip(player_dic, spell_dic, toplevel='', widget=''): toolTip = SpellWindow(widget=widget) def enter(event): toolTip.show(player_dic=player_dic, spell_dic=spell_dic) def leave(event): toolTip.hidetip() widget.bind('<Enter>', enter) widget.bind('<Leave>', leave) if __name__ == '__main__': player_dic, attribut_dic, spell_dic, inventory_dic = dictionnaires.dictionnaires_vierge( ) import manipulate_json as jm player_dic = jm.load_file('player_dic', 'Blue Dragon') attribut_dic = jm.load_file('attribut_dic', 'Blue Dragon') spell_dic = jm.load_file('spell_dic', 'Blue Dragon') inventory_dic = jm.load_file('inventory_dic', 'Blue Dragon') a = 0 if a == 0: w = SpellWindow(toplevel=True) w.show(player_dic=player_dic, spell_dic=spell_dic) else:
def show(self, stat_dic, name, level, image_dir, category='', x_relative=0, y_relative=0): if self.stats_window: return if type(self.widget) == str: if self.toplevel: self.stats_window = Toplevel() self.stats_window.wm_overrideredirect(1) self.stats_window.wm_geometry("+%d+%d" % (x_relative, y_relative)) self.stats_window.focus_force() else: self.stats_window = Tk() self.bold_font13 = "Constantia 13 bold" self.bold_font16 = "Constantia 16 bold" self.classic_font12 = "Constantia 12" self.classic_font16 = "Constantia 16" self.underline_font12 = "Constantia 12 bold underline" self.bold_font12 = "Constantia 12 bold" self.classic_font12 = "Constantia 12" else: x, y, cx, cy = self.widget.bbox("insert") x = x + self.widget.winfo_rootx() + 12 y = y + cy + self.widget.winfo_rooty() + 40 self.stats_window = Toplevel(self.widget) self.stats_window.wm_overrideredirect(1) self.stats_window.wm_geometry("+%d+%d" % (x + x_relative, y + y_relative)) self.bold_font13 = "Constantia 10 bold" self.bold_font16 = "Constantia 10 bold" self.classic_font16 = "Constantia 10" self.classic_font12 = "Constantia 10" self.underline_font12 = "Constantia 10 bold underline" self.bold_font12 = "Constantia 10 bold" self.classic_font12 = "Constantia 10" self.stats_window.title("Stats") self.stats_window.resizable(False, False) self.stats_window.iconbitmap("img/icone.ico") self.stats_window.option_add('*Font', 'Constantia 12') #self.stats_window.option_add('*Button.activebackground','darkgray') #self.stats_window.option_add('*Button.activeforeground','darkgray') #self.stats_window.option_add('*Button.relief','groove') #self.stats_window.option_add('*Button.overRelief','ridge') self.stats_window.option_add('*justify', 'left') self.stats_window.option_add('*bg', 'lightgray') self.stats_window.option_add('*compound', 'left') self.stats_canvas = Canvas(self.stats_window) self.stats_canvas.pack(fill=BOTH, expand=True, padx=20, pady=20) self.stat_dic = stat_dic self.img_dic = dictionnaires.dictionnaires_vierge(loadimg=True) itsimage = PhotoImage(file=image_dir) name_label = Label(self.stats_canvas, text=str(name), font=self.bold_font13, image=itsimage) name_label.grid(row=0, column=0) level_label = Label(self.stats_canvas, text=str(level), font=self.bold_font13, image=self.img_dic['starnoir']) level_label.grid(row=0, column=1) if len(category) > 0: category_label = Label(self.stats_canvas, text=str(category), font=self.bold_font13, image=self.img_dic[category]) category_label.grid(row=0, column=2) Frame(self.stats_canvas, height=10).grid(row=1) # Ecriture de tous les boutons # On ajoute 'name' pour pouvoir les identifier en cliquant dessus stat_name_list = list(self.stat_dic.keys()) stat_value_list = list(self.stat_dic.values()) import manipulate_json as jm attribut_dic = jm.load_file( fulldir="ressources/template/attribut_dic.json") imglist = [] ligne, colonne = 1, 0 k1 = 2 k2 = 0 for i in range(len(stat_name_list)): attribut_name = str(stat_name_list[i]) attribut_value = f"{stat_value_list[i]:0.1f}" color = str(attribut_dic[attribut_name]['color']) imglist.append( PhotoImage(file=attribut_dic[attribut_name]['image'])) l1 = Label(self.stats_canvas, text=f"{attribut_name} : {attribut_value}", fg=color, font=self.bold_font12, image=imglist[i]) l1.grid(row=ligne + k1, column=colonne + k2, padx=10, sticky=W) ctt.CreateToolTip(l1, attribut_dic[attribut_name]['description']) ligne += 1 if i == 5: ligne = 2 colonne = 1 if i == 10: ligne = 2 colonne = 2 if type(self.widget) == str: # Séparateur suivi du bouton 'Confirmer' Frame(self.stats_canvas, height=10).grid(row=i + k1 + 1) Button(self.stats_canvas, text="Confirmer", command=self.confirm).grid(row=i + k1 + 2, column=0, columnspan=10) self.stats_window.mainloop()