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 ()