简体   繁体   中英

python tkinter canvas size using scrollbar

Edited: I want the size of canvas1 to be adjusted using scrollbar . When I run this, only canvas1 is visible no place left on frame for canvas2 . I want canvas1 's size on the frame to be somewhere near 300*400 and when I scroll it to visualize the whole frame (1000*800)

I want to construct a frame with two canvas. but the problem is that i dont know how to fit first canvas within the scrollbar. In the following code the size of canvas is huge because of that the second canvas is not displayed in the frame. What i want is to fix the size of first canvas within the scrollbar. Am new to tkinter so have no idea how to do that i will really appreciate your help

root=Tk()

master=Frame(root,width=300,height=300)
master.grid(row=0,column=0)

xscrollbar = Scrollbar(master, orient=HORIZONTAL)
xscrollbar.grid(row=1, column=0, sticky=E+W)
yscrollbar = Scrollbar(master)
yscrollbar.grid(row=0, column=1, sticky=N+S)

canvas1=Canvas(master, width=1000, height=800, background='white',xscrollcommand=xscrollbar.set,yscrollcommand=yscrollbar.set)
canvas1.grid(row=0,column=0, sticky=N+S+E+W)
xscrollbar.config(command=canvas1.xview)
yscrollbar.config(command=canvas1.yview)

canvas2=Canvas(master, width=100, height=200, background='pink',xscrollcommand=xscrollbar.set,yscrollcommand=yscrollbar.set)
canvas2.grid(row=2,column=0)

mainloop()

您要执行的操作是将画布大小设置为300x400,然后将画布的scrollregion属性设置为1000 * 800。

canvas1 = Canvas(..., width=300, height=400, scrollregion=(0,0,1000,800))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM