Beispiel #1
0
def main():
    root = Tk()
    sizex = 800
    sizey = 600
    posx = 100
    posy = 100
    root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))

    root.grid()
    root.rowconfigure(0, weight=1)
    root.columnconfigure(0, weight=1)

    myframe = Frame(root, relief=GROOVE, bd=1)
    myframe.grid(row=0, column=0, sticky="NESW")

    myframe.rowconfigure(0, weight=1)
    myframe.columnconfigure(0, weight=1)
    myframe.columnconfigure(1, weight=0)

    canvas = Canvas(myframe)
    canvas.grid(row=0, column=0, sticky="NESW")

    frame = Frame(canvas)
    myscrollbar = Scrollbar(myframe, orient="vertical", command=canvas.yview)
    myscrollbar.grid(row=0, column=1, sticky="NESW")
    canvas.configure(yscrollcommand=myscrollbar.set)

    canvas.create_window((0, 0), window=frame, anchor='nw')
    frame.bind("<Configure>", lambda e, c=canvas: myfunction(c, e))
    data(frame)
    root.mainloop()
Beispiel #2
0
def main():
    root = Tk()

    frame = add_scrollbars(root, Frame, wheel=True)

    if False:

        def event_break(e):
            print("breaking %r" % e)
            return "break"

        frame.bind_all("<Button-4>", event_break, "+")

    lb = Label(frame, text="Label")
    lb.pack(fill=BOTH, side=TOP)

    cb = Combobox(frame, values=("1", "2", "3"))
    cb.pack(fill=BOTH, side=TOP)

    text = Text(frame)
    text.pack(fill=BOTH, expand=True, side=TOP)
    text.insert(END, "A\nMultiline\nMessage")

    for i in range(3, 100):
        text.insert(END, "line %d\n" % i)

    text2 = Text(frame)
    text2.pack(fill=BOTH, expand=True, side=TOP)

    for i in range(1, 200):
        text2.insert(END, "line %d\n" % i)

    bt1 = Button(frame, text="Bt#1")
    bt1.pack(side=LEFT)

    bt2 = Button(frame, text="Bt#2")
    bt2.pack(side=RIGHT)

    root.rowconfigure(2, weight=0)
    Label(root, text="Outer label").grid(row=2,
                                         column=0,
                                         columnspan=2,
                                         sticky="EW")

    if False:

        def event(e):
            print("event %r" % e)

        frame.bind("<Button-4>", event, "+")

    scrollable = set(["TCombobox", "Scrollbar", "Text"])

    def event_all(e):
        w = e.widget

        m = e.widget
        while m is not None:
            if m is frame:
                break
            m = m.master
        else:
            print("Outer widget")
            return

        cls = w.winfo_class()
        print("cls = " + cls)
        if cls in scrollable:
            return
        # scroll here

    bind_all_mouse_wheel(frame, event_all, "+")

    root.mainloop()
Beispiel #3
0
from six.moves.tkinter import (
    Tk,
    Canvas,
    Label,
    BOTH,
    Frame
)
from widgets import (
    CanvasFrame
)

if __name__ == "__main__":
    root = Tk()

    root.rowconfigure(0, weight = 1)
    root.columnconfigure(0, weight = 1)

    cnv = Canvas(root, bg = "white")
    cnv.grid(row = 0, column = 0, sticky = "NESW")

    cf = CanvasFrame(cnv, 100, 100)

    cnv.itemconfig(cf.id, width = 150, height = 150)

    Label(cf, text = "Test").pack(fill = BOTH, expand = 0)

    f2 = Frame(cf, bg = "white", width = 100, height = 100)
    f2.pack(fill = BOTH, expand = 1)

    def on_motion(e):