Hi
Wie kann man die Farbe von einem Button ändern, wenn man ihn drückt
(normalerweise besch)?
Button Farbe ändern
@Mätthi: Die Farbe kann man nachträglich mit der `configure()`-Methode verändern: ``button.configure(background='yellow')``
Jo, stimmt:

Code: Alles auswählen
In [44]: b.configure(background='besch')
---------------------------------------------------------------------------
<class `_tkinter.TclError`> Traceback (most recent call last)
/home/bj/<ipython console> in <module>()
/home/bj/lib-tk/Tkinter.py in configure(self, cnf, **kw)
1198 the allowed keyword arguments call the method keys.
1199
-> 1200 return self._configure('configure', cnf, kw)
1201 config = configure
1202 def cget(self, key):
/home/bj/lib-tk/Tkinter.py in _configure(self, cmd, cnf, kw)
1189 self.tk.call(_flatten((self._w, cmd, '-'+cnf))))
1190 return (x[0][1:],) + x[1:]
-> 1191 self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
1192 # These used to be defined in Widget:
1193 def configure(self, cnf=None, **kw):
<class `_tkinter.TclError`>: unknown color name "besch"
In [45]: b.configure(background='beige')
In [46]:

Du suchst wohl eher 'activebackground' statt 'background'. Hier etwas zum Experimentieren.
Siehe auch
http://effbot.org/tkinterbook/button.htm
oder
http://infohost.nmt.edu/tcc/help/pubs/t ... utton.html
yipyip
Code: Alles auswählen
import Tkinter as tk
def show_pressed(but):
but.config(activebackground='red')
def show_released(but):
but.config(activebackground='yellow')
root = tk.Tk()
but1 = tk.Button(root, text='Button1')
show_released(but1)
but1.bind('<ButtonPress-1>', lambda ev: show_pressed(but1))
but1.bind('<ButtonRelease-1>', lambda ev: show_released(but1))
but1.pack()
but2 = tk.Button(root, text='Button2', activebackground='cyan',
background='besch'.replace('sch', 'ige'))
but2.pack()
root.mainloop()
http://effbot.org/tkinterbook/button.htm
oder
http://infohost.nmt.edu/tcc/help/pubs/t ... utton.html

yipyip
Zuletzt geändert von Damaskus am Samstag 20. Juli 2013, 13:27, insgesamt 1-mal geändert.
Grund: Benutzernamen entfernt
Grund: Benutzernamen entfernt
Hallo zusammen
Hier noch die gekürzte yipyip-Variante:
Gruss zusammen wuf 
Hier noch die gekürzte yipyip-Variante:
Code: Alles auswählen
import Tkinter as tk
root = tk.Tk()
but1 = tk.Button(root, text='Button1', activebackground='yellow')
but1.bind('<ButtonPress-1>',
lambda ev: but1.config(activebackground='red'))
but1.bind('<ButtonRelease-1>',
lambda ev: but1.config(activebackground='yellow'))
but1.pack()
but2 = tk.Button(root, text='Button2', activebackground='cyan',
background='besch'.replace('sch', 'ige'))
but2.pack()
root.mainloop()

Take it easy Mates!
Richtig ich hatte nur keine zeit background auszuprobieren
activebackground war eigentlich richtig
nochmal Danke
activebackground war eigentlich richtig
nochmal Danke