Пример #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()
Пример #2
0
    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):
        print (e.x, e.y)

    f2.bind("<Motion>", on_motion, "+")

    root.mainloop()