Python GUI programming--scrollbar&&listbox

Source: Internet
Author: User

Absrtact: When programming with the Python process GUI, you often need to use the ListBox component, and how to control the display of the ListBox component, you need to use the ScrollBar component. This article focuses on the binding of actions between two GUI components--------the action of one component will start the corresponding action of another component.


1.Scrollbar Control

ScrollBar is the scroll bar, which is basically used in conjunction with Listboxs/canvases/text fields these controls. Horizontal scrollbar can also be used in conjunction with entry. 2.Scrollbar controls combined with other controls

By combining a vertical scrollbar and Listboxs/canvases/text fields these controls, you only need to follow the steps below: 1. Set the Yscrollcommand options for these controls to the ScrollBar set method. 2. Set the command option for ScrollBar to the Yview method for these controls. The following example combines Listboxs and scrollbar: The result and the code are as follows:

1 #!/usr/bin/python
  2 # encoding:utf-8
  3 from tkinter import *
  4 master = Tk ()
  5 scrollbar = ScrollBar (ma ster)
  6 scrollbar.pack (side=right, Fill=y)
  7 listbox = ListBox (Master, Yscrollcommand=scrollbar.set)
  8 For I in range (1000):
  9     listbox.insert (end, str (i))     listbox.pack (side=left, Fill=both)
 One scrollbar.config (Command=listbox.yview)
 Mainloop ()

Related Article

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.