Crear un botón gráfico personalizado, con 3 estados posibles (Activado, con el Roedor Encima, Normal), usando TK.
En la foto de pantalla se muestra el Ejemplo con el Ratón Encima (Mouse Over)
Requisitos: Es necesario saber usar encoding en Base64, que NO es cubierto por esta Receta, disculpe.
#!/usr/bin/env python # -*- coding: utf-8 -*- # Esto es okbutton.py import Tkinter class OkButton(Tkinter.Button): def __init__(self, master, data = 0, *args, **kwargs): if data: self.onImage = Tkinter.PhotoImage(data = kwargs['onImage']) self.offImage = Tkinter.PhotoImage(data = kwargs["offImage"]) self.activeImage = Tkinter.PhotoImage(data = kwargs["activeImage"]) else: self.onImage = Tkinter.PhotoImage(file = kwargs['onImage']) self.offImage = Tkinter.PhotoImage(file = kwargs["offImage"]) self.activeImage = Tkinter.PhotoImage(file = kwargs["activeImage"]) del kwargs['activeImage'], kwargs["onImage"], kwargs["offImage"] Tkinter.Widget.__init__(self, master, 'button', kwargs, args) self.bind("<Enter>", self.mouseOver) self.bind("<Leave>", self.mouseLeave) self.bind("<Button-1>", self.mouseClick) self.bind("<ButtonRelease-1>", self.mouseLeave) self.mouseLeave(None) def mouseOver(self, Event): self["image"] = self.onImage def mouseLeave(self, Event): self["image"] = self.offImage def mouseClick(self, Event): self["image"] = self.activeImage oexitOff = '''\ R0lGODlhXgAiAOf/AAABAAYAAAQABgUCBw0ACBMACRQACxUBDBMCEgkGDBAEDBkCFBYEDhsDEBIH DxwFERgHERwGEhsHFx8HGBUMEhoLEyEKGh8MFRcPFB4OGyINGycMHR0QFyMOHCQPHR0SHCUQHh4U HiMTHysRISAVIC0SIiQVICkUIi4TIyYWIioVIy4UJCIYIi8UJScXIzEWJi4YJioaJjQYKSsbKDIZ LSwcKTEbKi4eKjkdLjAgLDIhLjkfNDwgMDwiNzYlMj4jODwlNEAkNTgnND8lOjopNj8oN0MnN0Io PUUoOUEqOT4tOkQtO0csQUYvPkguQ0suP0QwQ0ovRUkxQEswRk4xQkozQkY1QlIxSEw0Q04zSEg2 Q001RE42RVA1SlM1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KOCABBZo4IEIEvgfJPwtkgghe4wBhAcMIOCZ QropxNsCD0zQwQYl4FAEFFJQwUUYXGCh4oostujiizDG2OKJXFAhxRNLJAGEDSdY8MACDFyYkEAL 8daABBZ4gIIMOPyABBNRTJFFF1lcYeWVWGap5ZZcdpnllFNMEQUTSPywgwwoeGCBSUEuRGRCB3Do YQk08HBEFGCcscYbc9zh55+ABirooHfEIYYZfRKqaKBzvLHGGWBEcQQPNJTQwQQ/XghAAHBiN8EG KOBwxBRnwPFHIY1UYgkmm2yiyav+sMYq66ywekEAQRz8QSuscwBgQqyXmABADZZU0kghf8BxxhRH 4IDCBpi2WcBBBfDW4QYv8MAEGXMUIkknpaCyCiyy1GLuuegaokMNjKDrbi2zxCBQBT7kUBEAebx7 LiIAfICuDwBg0Aosq6BSSieSFDIHGUzw8AK0D7SJUAEILBATCtqecUcknahSCzDDHKPMMiQ3Y/LJ ySQhkADDnOzyyVwIlMrJy7Qh88snbwJACidjAQAFwyyjzDHDAFOLKp1EcscZDaNQ0gIIaMihBSEy cUYglpxSizDLODONNtpw083YZHejzQ0DDVP22t0YIxAtbEsBQAxsj53K3GOn8XP+NN1wA/Y0ziwz TC2nWBII0ziU4OMCbBGAQAMTeECDEWTcYQkqviRDjTbfjENOOaCjI/roKguEy+ioo04HADmkLvo0 AkXjOjqxAHADOjZToA06oJdDzjjfaENNMr6gYskdZBhBgwcTNIAARdh1gPEUcERyii/LXPMNOeio w8734IPvx0CghG8++DkAoMj533MAwCjs08J67uCcrw465HxzzTK+nBIJHFPggdMiVhGLdUAGRyjD IDpRi2RorxzeA1884qGNNiQhHrkYiB0myMEOdpACAEiFBzkoBPWNMB64IMg3PBg+dZRDf8moRScG UYYjyOBpAoFciKIAB0moYhj+1PhGOb43QiLI7F4+OOEJQcgKJRYBAIg4YQYFIJAQrPCE33shNYah CknAIQqJa55AHmABFPSgC3fQxCyUoQ1yeI+D8oijPLZQEAegQ454zGMcawAAS+gxjiR43x95wbpv sAAACdBGHjnIDnW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lwdolltY5pg4pmtoxnq4VotpBqhHtyeIpppY1orJFrhYFxeYlp snxzeY5prZJshpRri5JrkYpqs49qrpNth5NrnphsiJRuiJNrqpltiZJumZVviZpuipZvlYF4fptv i5lum5NvpppvnJ1wjJRwp5hwo4N6gJtxk55xjZ5wmJlxpIR7gZxxn59yjp9xmZ1yoKBzj550lp5z oaF0kKFzm4d+hJ91l6J1kaJ0nIh/haF2mKN1naR3k6J3mYqBh6N4moyDiY2Eio6Fi4+GjJCHjZGI jpWMkpaNk5iPlZySmJ2TmZ6UmqWboaacoqKfo6OgpKqhp6yjqa2kqqmnq6qorK6ssK+tsbWytv// //////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////yH+EUNyZWF0ZWQgd2l0aCBH SU1QACH5BAEKAP8ALAAAAABeACIAAAj+AAEIHEiQYIECAxIqXMiwocOHECM6PFiwokWLEjNq3MjR 4cWPAyMaSJDAgMmTKFOqXMmyZUqSJQ08BFlRZIUnc9Jo2cmzp8+fQIMK9ZkGTxosPSDI9EgTAEQD C3pIgnbtmrWrWLNq3cq1q1et17Bdq/bsUI+STD8+XTCGGbVu3uLKnUu3rt27ePN64zZt2RilaWs+ HFkF2bRs2rYpXsy4sePHkCNL3qYt27RjY06gZYgRYoIepZpFk0a6tOnTqFOrXs36dDRnxRzhSBBY 4NMKeoAhU8a7t+/fwIMLH048eLJjvOZUWLqw4GCTGtqUakW9uvXr2LNr3859eylKZpb+B26Y0gGN MXDS19FTp7379/Djy59PXz779OnbfEGi2WTDkAydBBMDGJQAgwwy6ACEDgw26OCDEEYo4YQRLoig DC2k8IEEDMTEnEK2LSRgAgxEYAEHIKRgggkvtOjiizDGKOOMNNYIw4opgMDBBRF06CFnTilkEkkl XgCCCTHcwMMRRjChxJNQRinllFQKsYMPRVCpJZVMGHEEDzfEYAIIPProH4gIJTQkiRZ0YMINRzhB RRdhkIHGnWvkqeeefPap5xITBBpoBlf4qecUE4SwJxohTIACGWF0QYUTR9xgQgcWmMncQWqOlM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1z7eOe+gCE2oQhfauwT6Qnvc894NCECTAgSBcIZDnOIwx9GOevSjIA3G6GhoOtRxIQj+bIoI lta0p0VtamKLqUxnSlOaug1ucqOb3UTQlIIEIAYXy9jGOvayohr1qEg9Ks50xjM5xCAAPb1IA24Q hj6Mq1zn2pdWt8rVrnb1XARrRB/CcIMGNCUgADs= '''
Ejemplo: (es el de la foto).
#!/usr/bin/env python # -*- coding: utf-8 -*- # License: GPLv3 #import this try: from Tkinter import * # Python2 except ImportError: from tkinter import * # Python3 ################################################################ from okbutton import * # This is the file, from the example ^_^ ################################################################ root = Tk() root.title('Boton') root.focus() root.resizable(0, 0) botoncito = OkButton(root, 1, onImage = oexitOn, offImage = oexitOff, activeImage = oexitActive, bd = 0, relief='flat', cursor='hand2', command = root.destroy) botoncito.pack() root.mainloop()
Disclaimer: el uso o no de SheBang/Declaracion de Encoding queda a criterio del usuario.