Python_ the Tkinter frame with a scroll bar __python

Source: Internet
Author: User

Problem background: When the interface needs to display more content, need to use scroll bar ScrollBar, Official document said ScrollBar can only with the following controls (canvas, entry, ListBox, text) combined. But if I want ScrollBar to be combined with frame.

The solution is to put the frame inside the canvas (such as filling the entire canvas), canvas with ScrollBar, so scrolling canvas is equivalent to rolling the frame.

Give me a chestnut.

Canvas=canvas (root,width=200,height=180,scrollregion= (0,0,520,520)) #创建canvas
canvas.place (x = +, y = 265) # Place canvas position
frame=frame (canvas) #把frame放在canvas里
frame.place (width=180, height=180) #frame的长宽, and canvas similar
Vbar=scrollbar (canvas,orient=vertical) #竖直滚动条
vbar.place (x = 180,width=20,height=180)
vbar.configure (Command=canvas.yview)
Hbar=scrollbar (canvas,orient=horizontal) #水平滚动条
hbar.place (x =0,y=165,width=180,height=20)
Hbar.configure (Command=canvas.xview)
canvas.config (xscrollcommand=hbar.set,yscrollcommand=vbar.set) #设置  
Canvas.create_window ((90,240), window=frame)  #create_window

Of course, if it is plain text scrolling, you can choose the Scrolltext component, its function and text, you can refer to this link https://www.jianshu.com/p/abea88607525

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.