Checkbutton
Eigenschaften
Erzeugen:
chk = tkinter.Entry(self)
Beschriftung:
self.chk["text"] = "Bestanden"
Setter/Getter:
self.var_name = tkinter.BooleanVar()
self.var_name.set(True)
self.chk["variable"] = self.var_name
Layout-Manager:
self.chk.pack oder self.textui.grid()
ActiveBackground:
self.chk.config(activebackground= "yellow")
funktioniert nicht bei Tests
ActiveForeground:
self.chk.config(activeforeground = "green")
funktioniert nicht bei Tests
Background:
self.chk.config(background = "green")
self.chk.config(background = "#FF0000")
self.chk.config(bg = "#FF0000")
Foreground:
self.chk.config(foreground="red")
self.chk.config(fg="red")
Borderwidth:
self.chk.config(borderwidth="2") #pixel
Borderwidth:
self.chk.config(bd="2") # pixel
Height:
self.chk.config(height="2") # Textzeilen
Justify:
self.chk.config(justify("left")
self.chk.config(justify("right")
self.chk.config(justify("justify")
overrelief:
self.chk.config(overrelief="raised") Mouse Hover
sunken
flat
ridge
solid
groove
relief:
self.chk.config(relief="raised")
sunken
flat
ridge
solid
groove
state:
self.chk.config(state="normal")
active
enabled
disabled
Beispiel
import tkinter # from Tkinter import * class MyApp(tkinter.Frame): def __init__(self, master=None): tkinter.Frame.__init__(self, master) self.pack() self.setGUI() def setGUI(self): self.group = tkinter.LabelFrame(self, text="Noten") self.group.pack(fill="both", expand="yes") self.chk1= tkinter.Checkbutton(self) self.chk1["text"] = "Eins" self.chk1.pack() self.chk2= tkinter.Checkbutton(self) self.chk2["text"] = "Zwei" self.chk2.pack() self.chk3= tkinter.Checkbutton(self) self.chk3["text"] = "Drei" self.chk3.pack() self.chkProperty1 = tkinter.BooleanVar() self.chkProperty1.set(True) self.chk1["variable"] = self.chkProperty1 self.chkProperty2 = tkinter.BooleanVar() self.chkProperty2.set(False) self.chk2["variable"] = self.chkProperty2 self.chkProperty3 = tkinter.BooleanVar() self.chkProperty3.set(False) self.chk3["variable"] = self.chkProperty3 self.bnOk = tkinter.Button(self) self.bnOk["text"] = "Abbruch" self.bnOk["command"] = self.quit self.bnOk.pack(side="right") self.bnTest = tkinter.Button(self) self.bnTest["text"] = "Test Checkbox" self.bnTest["command"] = self.onTestChk self.bnTest.pack(side="right") def onTestChk(self): print( str(self.chkProperty1.get()) ) print( str(self.chkProperty2.get()) ) print( str(self.chkProperty3.get()) ) root = tkinter.Tk() root.title("CheckBox") root.geometry("250x150") app = MyApp(root) app.mainloop()