ich habe eine Buttonklasse geschrieben, und will davon nun mehrere Buttons in einem Frame packen. Etwa so:
Code: Alles auswählen
# -*- coding: cp1252 -*-
import Tkinter as tk
class HLButton(tk.Label):
def __init__(self, master, command = (None, []), ev = False, relief = 'raised', hvcolor = '#7777ff', \
bg = 'SystemButtonFace', **dargs):
# command should be a method of <master>
self.hvcolor = hvcolor
self.bgcolor = bg
self.command = command
tk.Label.__init__(self)
self.config(relief = relief, bg = self.bgcolor, **dargs)
if ev:
self.bind('<Button-1>', lambda ev: self.command[0](ev))
else:
self.bind('<Button-1>', lambda ev: self.command[0](*self.command[1]))
self.bind('<Enter>', lambda ev: ev.widget.config(bg = self.hvcolor), '+')
self.bind('<Leave>', lambda ev: ev.widget.config(bg = self.bgcolor), '+')
if __name__ == '__main__':
root=tk.Tk()
f = tk.Frame(root)
# f.pack()
bt = []
for i in range(4):
h = HLButton(f, command = (root.destroy, []), text = 'Schließen')
h.pack(side = 'left', fill = 'x', expand = True)
bt.append(h)
root.mainloop()
mfg pysq
frohe Weihnachten : )