In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Most people do not understand the knowledge points of this article, "what are the ways to use Tkinter components Scrollbar?", so the editor summarizes the following, detailed contents, clear steps, and a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Tkinter components Scrollbar usage" article.
The Scrollbar (scroll bar) component is used to scroll the visible range of some components, which can be divided into vertical scroll bar and horizontal scroll bar according to the direction. Scrollbar components are often used to scroll text, canvas, and list boxes.
When to use Scrollbar components?
Scrollbar components are usually used almost with Text components, Canvas components, and Listbox components, and horizontal scroll bars can also be used with Entry components.
Usage
The following example shows how to use a vertical scroll bar. To install a vertical scroll bar on a component, you need to do two things:
1. Set the yscrollbarcommand option of the component to the set () method of the Scrollbar component
two。 Set the command option of the Scrollbar component to the yview () method of the component.
Import tkinter as tk root = tk.Tk () sb = tk.Scrollbar (root) sb.pack (side= "right", fill= "y") lb = tk.Listbox (root, yscrollcommand=sb.set) for i in range (1000): lb.insert ("end", str (I) lb.pack (side= "left", fill= "both") sb.config (command=lb.yview) root.mainloop ()
Analysis: when the visual range of the Listbox component changes, the Listbox component notifies the Scrollbar component by calling the set () method. When the user manipulates the scroll bar, the yview () method of the Listbox component is automatically called.
The method of adding a horizontal scroll bar is the same as above, except that you can change yscrollcommand to xscrollcommand,yview to xview.
Parameters.
Scrollbar (master=None, * options) (class)
Master-parent component
* * options-component options. The specific meaning and usage of each option are listed in the table below:
Option means activebackground1. Specifies the background color of the slider and arrowhead when the mouse floats over
two。 The default value is specified by the system activerelief1. Specifies the style of the slider when the mouse floats over it
two。 The default is "raised"
3. Can choose "flat", "sunken", "groove", "ridge" background1. Specify background color
two。 The default value is specified by the system, bg is the same as background borderwidth1. Specify border width
two。 The default value is 0bd, like borderwidth, command1. The function to call back when the scroll bar is updated
two。 It is common to specify the xview () or yview () method cursor1 of the corresponding component. Specifies the mouse style when the mouse floats over the top
two。 The default value is specified by the system elementborderwidth1. Specify the border width of scroll bars and arrows
two。 The default value is-1 (for the value using the borderwidth option) highlightbackground1. Specifies the color of the highlighted border when the scroll bar does not get focus
two。 The default value is specified by the system highlightcolor1. Specifies the color of the highlighted border when the scroll bar gets focus
two。 The default value is specified by the system highlightthickness1. Specify the width of the highlighted border
two。 The default value is 0 (without a highlighted border) jump1. Specifies the behavior when the user drags the scroll bar
two。 The default value is False, and any change in the scroll bar immediately calls the callback function specified by the command option.
3. Set to True to call orient1. Exe when the user releases the mouse. Specify whether to draw "horizontal" (vertical scroll bar) or "vertical" (horizontal scroll bar)
two。 The default value is VERTICALrelief1. Specify the border styl
two。 The default is "sunken"
3. Can choose "flat", "raised", "groove", "ridge" repeatdelay1. This option specifies the response time for the left mouse button to click on the scroll bar notch
two。 The default value is 300 (millisecond) repeatinterval1. This option specifies the response interval when the left mouse button presses the scroll bar groove
two。 The default value is 100 (millisecond) takefocus1. Specifies that the focus can be moved to the Scrollbar component using the Tab key
two。 The default is on, and you can set this option to False to avoid focusing on this component troughcolor1. Specify the color of the groove
two。 The default value is specified by the system width1. Specify the width of the scroll bar
two。 The default value is 16 pixel method
Activate (element)
-- displays the background color and style of the element specified by the element parameter
-- the element parameter can be set to: "arrow1" (arrow 1), "arrow2" (arrow 2), or "slider" (slider)
Delta (deltax, deltay)
Given a range of mouse movement deltax and deltay (in pixels, deltax represents horizontal movement, deltay represents vertical movement), and then the method returns a value of floating point type (range-1.01.0)
This is usually used on mouse bindings to determine how the slider moves when the user drags the mouse
Fraction (x, y)
Given a pixel coordinate (x, y), this method returns the position of the scroll bar closest to the given coordinate (range 0.0-1.0)
Get ()
-returns the position of the current slider (a, b)
-the a value indicates the position of the top or left end of the current slider, and the b value indicates the position of the bottom or right end of the current slider (range 0.0 ~ 1.0)
Identify (x, y)
Returns a string representing the scroll bar widget at the specified location (if any)
The return value can be: "arrow1" (arrow 1), "arrow2" (arrow 2), "slider" (slider) or "" (nothing)
Set (* args)
-- sets the position of the current scroll bar
-if set, two parameters are required (first, last). First represents the position of the top or left end of the current slider, and last represents the position of the bottom or right end of the current slider (range 0. 0-1. 0)
The above is about the content of this article on "how to use Tkinter components Scrollbar". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.