In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to achieve Tkinter canvas canvas parameters, delete components, add vertical scroll bars", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement the canvas parameters of Tkinter canvas, delete components, and add vertical scroll bars.
Catalogue
1. Parameters of canvas Canvas
2. Delete the components under the mouse
3. Canvas with vertical scroll bar
1. The parameters of canvas Canvas from tkinter import * win = Tk () win.geometry ('500x500' 500 '100') canvas = Canvas (master=win, # parent control bg='orange', # background color bd=2, # frame width closeenough=1, # when the distance between the mouse and the component on the canvas is less than this value, the mouse is considered to be a floating-point value cursor='circle' on the component # the style that the mouse flies over height=300, # the high width=300 of the canvas, # the wide highlightbackground='blue', of the canvas # the color of the highlight border when it does not get focus highlightcolor='red', # the color of the highlight border when it gets focus highlightthickness=5, # the width of the highlight border relief='groove', # the style of the border flat, groove, raised, ridge, solid Or sunken state='normal', # status normal or disabled scrollregion= (0,0,400,400), # the range in which the canvas can be scrolled confine=True, whether the canvas is allowed to scroll beyond the range specified by the scrollregion option selectbackground='yellow', # the background color selectborderwidth=10 when the canvas object is selected, and the border width takefocus=True when the canvas object is selected # whether you can use the Tab key to move the focus to the yscrollcommand=None in the input box, # set the vertical scroll bar, generally associate with the scroll bar, use yscrollincrement=1, # set the step size xscrollcommand=None of the vertical scroll bar, # set the horizontal scroll bar, and generally use xscrollincrement=1 associated with the scroll bar # set the step size of the horizontal scroll bar) canvas.pack (pady=50) canvas.create_window ((100,100), window=Entry (canvas)) Button (win, text=' button'). Pack () win.mainloop ()
2. Delete the components under the mouse from tkinter import * def event (w): # current means to delete the components under the mouse canvas.delete ('current') win = Tk () win.geometry (' 500x500) canvas.pack (fill=BOTH, expand=True) # draw solid lines, fill in orange, and set the width to 10for i in range (10,200,20): canvas.create_line (I, 100,200, width=10) Fill='orange') # bind left mouse button click event canvas.bind ('', event) win.mainloop ()
3. Canvas from tkinter import * def event2 () with vertical scroll bar: for i in range (0220): # draw solid line, fill it with pink, set width to 10 canvas.create_line (0, I, 100, I, fill='pink', width=10) for i in range (230,300): # draw solid line, fill in blue, set width to 50 canvas.create_line (0, I, 100, I) Fill='blue', width=50) def event1 (event): property delta parsing of "" event in MouseWheel event, positive values represent scroll up and negative values represent volume down Under Window, it is usually a multiple of 120 Under MacOS, "" number = int (- event.delta / 120) canvas.yview_scroll (number, 'units') win = Tk () win.geometry (' 500x500 / 500 / 100') frame = Frame (win) sv = Scrollbar (frame) # defines the vertical scroll bar sv.pack (side=RIGHT, fill=Y) # places the vertical scroll bar on the far right, occupying the full Y axis canvas = Canvas (frame, bd=2, bg='orange') Relief='groove') canvas.pack () canvas.config (yscrollcommand=sv.set) # sets the Y-axis scroll bar function of the canvas to bind canvas.config to the vertical scroll bar (scrollregion= (0,0,300) Sv.config (command=canvas.yview) # sets the range of the canvas to scroll (command=canvas.yview) # sets the function of the vertical scroll bar and binds the canvas Y scroll bar event frame.pack (pady=50) canvas.config (yscrollincrement=1) # sets the scroll bar step canvas.bind (", event1) # adds the wheel event Button (text=' adds components for the canvas', command=event2). Pack () event2 () win.mainloop ()
At this point, I believe you have a deeper understanding of "how to implement Tkinter canvas canvas parameters, delete components, and add vertical scroll bars". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.