Scrollbar
Eigenschaften
Benutzung:
Mit einer Listbox
Mit einem Editor (Text)
Erzeugen:
sbx = tkinter.Scrollbar(editorframe, orient="horizontal")
sbx.pack(fill="x", side="bottom")
sby = tkinter.Scrollbar(editorframe)
sby.pack(fill="y", side="right")
Setter/Getter:
self.editor["xscrollcommand"] = sbx.set
sbx["command"] = self.editor.xview
self.editor["yscrollcommand"] = sby.set
sby["command"] = self.editor.yview
Layout-Manager:
Immer in Verbindung eines Labelframes
self.rb1.pack oder self.rb1.grid()
ActiveBackground:
self.sb.config(activebackground= "yellow")
funktioniert nicht bei Tests
ActiveForeground:
self.sb.config(activeforeground = "green")
funktioniert nicht bei Tests
Background:
self.sb.config(background = "green")
self.sb.config(background = "#FF0000")
self.sb.config(bg = "#FF0000")
Foreground:
self.sb.config(foreground="red")
self.sb.config(fg="red")
Borderwidth:
self.sb.config(borderwidth="2") #pixel
Borderwidth:
self.sb.config(bd="2") # pixel
Height:
self.sb.config(height="2") # Textzeilen
Justify:
self.sb.config(justify("left")
self.sb.config(justify("right")
self.sb.config(justify("justify")
overrelief:
self.sb.config(overrelief="raised") Mouse Hover
sunken
flat
ridge
solid
groove
relief:
self.sb.config(relief="raised")
sunken
flat
ridge
solid
groove
state:
self.sb.config(state="normal")
active
enabled
disabled
Beispiel Editor
# coding=utf8 import tkinter from tkinter import messagebox class MyApp(tkinter.Frame): def __init__(self, master=None): tkinter.Frame.__init__(self, master) self.pack(expand=True, fill="both") # dialog zoomt self.setGUI() def setGUI(self): # pack ist wie das DockPanel in WPF # erst muessen die "normalen" UI-Elemente eintgetragen werden # am Schluss werden die UI-Elemente eingetragen, die fill="both" haben buttonframe = tkinter.Frame(self) # „JPanel“ fuer die Eingabe buttonframe.config(background = "blue") #"#FF0000" # 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(borderwidth="5") self.bnAction.config(activebackground= "yellow") # nun ein Editor mit fill=both editorframe = tkinter.Frame(self) # „JPanel“ fuer den Editor editorframe.config(background = "green") #"#FF0000" editorframe.pack(expand=True,fill="both", side="top" ) sbx = tkinter.Scrollbar(editorframe, orient="horizontal") sbx.pack(fill="x", side="bottom") sby = tkinter.Scrollbar(editorframe) sby.pack(fill="y", side="right") self.editor = tkinter.Text(editorframe) self.editor.config(wrap="none") # wrap="word" word char self.editor.pack(expand=True, fill="both", padx="5",pady="5") self.editor["xscrollcommand"] = sbx.set sbx["command"] = self.editor.xview self.editor["yscrollcommand"] = sby.set sby["command"] = self.editor.yview 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("Scrollbar Editor") root.geometry("450x400") app = MyApp(root) app.mainloop()
Beispiel Listbox
# coding=utf8 import tkinter from tkinter import messagebox class MyApp(tkinter.Frame): def __init__(self, master=None): tkinter.Frame.__init__(self, master) self.pack(expand=True, fill="both") # dialog zoomt self.setGUI() def setGUI(self): # pack ist wie das DockPanel in WPF # erst muessen die "normalen" UI-Elemente eintgetragen werden # am Schluss werden die UI-Elemente eingetragen, die fill="both" haben buttonframe = tkinter.Frame(self) # „JPanel“ fuer die Eingabe buttonframe.config(background = "blue") #"#FF0000" # 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(borderwidth="5") self.bnAction.config(activebackground= "yellow") # nun ein Editor mit fill=both frame1 = tkinter.Frame(self) # „JPanel“ fuer den Editor frame1.config(background = "green") #"#FF0000" frame1.pack(expand=True,fill="both", side="top" ) sbx = tkinter.Scrollbar(frame1, orient="horizontal") sbx.pack(fill="x", side="bottom") sby = tkinter.Scrollbar(frame1) sby.pack(fill="y", side="right") self.listbox = tkinter.Listbox(frame1,selectmode="extended") self.listbox.pack(fill="both",expand=True) self.listbox["yscrollcommand"] = sbx.set sbx["command"]=self.listbox.xview self.listbox["yscrollcommand"] = sby.set sby["command"]=self.listbox.yview for i in range(20+1): self.listbox.insert("end",str(i)) self.listbox.insert("end","abcdefghijklmnopqrstuvwxyz 0123456789") def onAction(self): messagebox.showinfo( "Hello Python", "Action") root = tkinter.Tk() root.title("Scrollbar Listbox") root.geometry("450x400") app = MyApp(root) app.mainloop()