Frame
Eigenschaften
Anwendung:
Gruppieren von UI-Elementen
- Label/Entry
- Checkbuttons
- Listbox/Scrollbar
- Editor/Scrollbars
Erzeugen:
frame = tkinter.Frame(self) # „JPanel“ fuer die Eingabe
Layout-Manager:
self.frame.pack(fill="x", side="top" )
self.frame.pack(expand=True, fill="both", side="top" )
oder
self.bn.grid()
ActiveBackground:
self.frame.config(activebackground= "yellow")
funktioniert nicht bei Tests
ActiveForeground:
self.frame.config(activeforeground = "green")
funktioniert nicht bei Tests
Background:
self.bn.config(background = "green")
self.bn.config(background = "#FF0000")
self.bn.config(bg = "#FF0000")
Foreground:
self.frame.config(foreground="red")
self.frame.config(fg="red")
Borderwidth:
self.frame.config(borderwidth="2") #pixel
Borderwidth:
self.frame.config(bd="2") # pixel
Height:
self.frame.config(height="2") # Textzeilen, Unsinn
Justify:
self.frame.config(justify("left")
self.frame.config(justify("right")
self.frame.config(justify("justify")
overrelief:
self.frame.config(overrelief="raised") Mouse Hover
sunken
flat
ridge
solid
groove
relief:
self.frame.config(relief="raised")
sunken
flat
ridge
solid
groove
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): buttonframe = tkinter.Frame(self) # „JPanel“ fuer die Eingabe buttonframe.config(background = "blue") # ohne expand, da fill=“x“ buttonframe.pack(fill="x", side="bottom" ) self.bnEsc = tkinter.Button(buttonframe) self.bnEsc["text"] = "Beenden" self.bnEsc["command"] = self.quit self.bnEsc.pack(padx="5", side="right") self.bnAction = tkinter.Button(buttonframe) self.bnAction["text"] = "Action" self.bnAction["command"] = self.onAction self.bnAction.pack(side="right") self.bnAction.config(foreground= "green") self.bnAction.config(activebackground= "yellow") def onAction(self): str = self.var_name.get() messagebox.showinfo( "Hello Python", str) self.editor.insert("end",str+"\r\n") root = tkinter.Tk() root.title("Button") root.geometry("250x150") app = MyApp(root) app.mainloop()