Hallo sea-live
Hier ist etwas zum experimentieren:
Code: Alles auswählen
# wuf_ref: scrolled_canvas_01_02.py
import Tkinter as tk
#~~ Tkinter-Logo 16x16
TK_SYMBOL = """
R0lGODlhDgALAID/AP8AAMDAwCH5BAEAAAEALAAA
AAAOAAsAQAIfDI4Qu8pukJmvJtgazppyBkbX8ZCh
Y57ohJmJl6JKAQA7GhQAOzu6CkQUAAA7Ow==
"""
COLOR_BG_SCROLLBAR = 'gray80'
def scrolled_canvas_test():
master = tk.Tk()
master.geometry('600x600')
master.title('Sitzplatzbelegungsanzeige LWCH 2009 ')
#~~ Hauptrahmen
scroll_frame = tk.Frame(master, bd=0)
scroll_frame.pack(side='top', fill='both', expand='yes')
#~~ Behaelter fuer die Canvas und die vertikale Ziehleiste
container_top = tk.Frame(scroll_frame, bd=0,
highlightthickness=0)
container_top.pack(side='top', fill='both', expand='yes')
#~~ Behaelter fuer die horizontale Ziehleiste und das Tk-Logo
container_bottom = tk.Frame(scroll_frame, bd=0,
highlightthickness=0)
container_bottom.pack(side='top',fill='x')
#~~ Canvas-Flache fuer grafischen Objekte
zeichenflaeche = tk.Canvas(container_top, bd=0, relief='sunken',
highlightthickness=0)
zeichenflaeche.pack(side='left', fill='both', expand='yes')
#~~ Vertikale Ziehleiste
y_scrollbar = tk.Scrollbar(container_top , bd=1, orient='vertical',
bg=COLOR_BG_SCROLLBAR, highlightthickness=0,
activebackground=COLOR_BG_SCROLLBAR)
y_scrollbar.pack(side='left', fill='y')
#~~ Horizontale Ziehleiste
x_scrollbar = tk.Scrollbar(container_bottom, bd=1, orient='horizontal',
bg=COLOR_BG_SCROLLBAR, highlightthickness=0,
activebackground=COLOR_BG_SCROLLBAR)
x_scrollbar.pack(side='left',fill='x',expand='yes')
#~~ Canvas fuer das Tkinter-Logo
logo_width = logo_height = 16
tk_logo = tk.Canvas(container_bottom, bd=1, relief='raised',
width=logo_width, height=logo_height, highlightthickness=0)
tk_logo.pack(side='left')
#~~ Tk-Logo-Symbol
master.tk_logo = tk.PhotoImage(data=TK_SYMBOL)
#~~ Tkinter-Logo
my_logo = tk_logo.create_image(logo_width/2, logo_height/2,
image=master.tk_logo, anchor='center')
#~~ Binde die vertikale & horizontale Ziehleisten an das Canvas-Objekt
zeichenflaeche.config(xscrollcommand = x_scrollbar.set)
zeichenflaeche.config(yscrollcommand = y_scrollbar.set)
x_scrollbar.config(command = zeichenflaeche.xview)
y_scrollbar.config(command = zeichenflaeche.yview)
#~~ Zeichne zwei Rechtecke auf die Canvas
zeichenflaeche.create_rectangle(0,0, 1600, 1650, fill='blue', width=0)
zeichenflaeche.create_rectangle(300, 300, 1000, 1000, fill='khaki')
#~~ Ermittle den noetigen Ziehbereich
zeichenflaeche.config(scrollregion=zeichenflaeche.bbox(tk.ALL))
if __name__ == '__main__':
scrolled_canvas_test()
tk.mainloop()
Ausgetestet unter SuSE11.0 & Python2.5
Gruss wuf
