import tkinter as tk import traceback from __main__ import * class MiniButton: def __init__(self,root,width=72,height=38,text="button"): self.text=text self.rb = tk.Frame(root, highlightbackground = "lightgrey", highlightthickness = 1, bd=0) self.bb = tk.Canvas(self.rb, highlightbackground = "black", highlightthickness = 1, bd=1,relief=tk.RAISED) self.bb.configure(width=width, height=height) self.fg = "#002" self.label = [] self.bind("", self.on_enter) self.bind("", self.on_leave) # !! BLOCK's other bindings like GO #self.bind("", self.on_b1) #self.bind("", self.on_press) #self.bind("", self.on_release) #self.bind("", self.on_release) self.activebackground="lightgrey" self.defaultBackground="grey" def on_b1(self, e): print("on_b1",e) #self.bb.config(background=self.activebackground) self.bb.config(relief=tk.SUNKEN)#abackground=self.activebackground) return 1 def on_press(self, e): print("on_press",e) #self.bb.config(background=self.activebackground) self.bb.config(relief=tk.SUNKEN)#abackground=self.activebackground) return 1 def on_release(self, e): print("on_release",e) #self.bb.config(background=self.activebackground) self.bb.config(relief=tk.RAISED)#abackground=self.activebackground) return 1 def on_enter(self, e): #print("on_enter",e) #self.bb.config(background=self.activebackground) self.bb.config(relief=tk.FLAT)#abackground=self.activebackground) return 1 def on_leave(self, e): #print("on_leave",e) self.bb.config(background=self.defaultBackground) self.bb.config(relief=tk.RAISED)#abackground=self.activebackground) return 1 def _label(self,text="1\n2\n3\n"): z = 0 self.bb.delete("label") self.label = [] for t in text.split("\n"): self.l = self.bb.create_text(37,z*10+9,text=t,anchor="c",tag="label") #self.l["color"] = self.fg self.label.append(self.l) z+=1 def _configure(self,**args): if "text" in args: if self.text != args["text"]: self.text = args["text"] self._label(self.text) if "bg" in args: #print(dir(self.bb)) self.bb.configure(bg=args["bg"]) self.defaultBackground=args["bg"] if "fg" in args: #print(dir(self.bb)) self.fg=args["fg"] #if len(self.label): # self.label[0].configure(color="red") #args["fg"]) #self.defaultBackground=args["fg"] def configure(self,**args): self._configure(**args) def config(self,**args): self._configure(**args) def bind(self,etype="