Jan-04-2020, 08:39 AM
sorry i don't know english well
Did scrolling objects on canvas through the canvas.move () method - changing the coordinates of the object when scrolling the mouse wheel (canvas2.bind_all ("MouseWheel", fun_mooving)). Everything turned out fine, all objects (canvas.create_text, canvas.create_image) move as they should. But the problem surfaced when I add a few objects of type Entry (canvas) to the canvas. If you smoothly turn the mouse wheel, then there is a noticeable slight delay when moving Entry objects, while other objects (texts, pictures) move without problems, as they should. If the mouse wheel is twisted sharply, then the coordinates when moving the Entry can be completely lost - do not get up to the coordinates put by it. What could be the problem?
Did scrolling objects on canvas through the canvas.move () method - changing the coordinates of the object when scrolling the mouse wheel (canvas2.bind_all ("MouseWheel", fun_mooving)). Everything turned out fine, all objects (canvas.create_text, canvas.create_image) move as they should. But the problem surfaced when I add a few objects of type Entry (canvas) to the canvas. If you smoothly turn the mouse wheel, then there is a noticeable slight delay when moving Entry objects, while other objects (texts, pictures) move without problems, as they should. If the mouse wheel is twisted sharply, then the coordinates when moving the Entry can be completely lost - do not get up to the coordinates put by it. What could be the problem?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
import tkinter as tk from tkinter import * global v_entry root = tk.Tk() root.geometry( '600x800+10+10' ) root.resizable(width = False , height = False ) def xxx(): global v_entry, list_v txt1 = 'txt1txt1txt1txt1txt1txt1txt1' v_01 = canvas2.create_text( 30 , 10 , text = txt1, anchor = NW) v_entry[ 0 ] = Entry(canvas2, bd = 0 , justify = CENTER, bg = '#7F7F7F' , width = 6 ) (v_entry[ 0 ]).insert( 0 , '000' ) (v_entry[ 0 ]).place(x = 100 , y = 25 ) txt1 = 'txt2txt2txt2txt2txt2txt2txt2' v_02 = canvas2.create_text( 30 , 50 , text = txt1, anchor = NW) v_entry[ 1 ] = Entry(canvas2, bd = 0 , justify = CENTER, bg = '#7F7F7F' , width = 6 ) (v_entry[ 1 ]).insert( 0 , '101' ) (v_entry[ 1 ]).place(x = 100 , y = 75 ) txt1 = 'txt3txt3txt3txt3txt3txt3txt3' v_03 = canvas2.create_text( 30 , 100 , text = txt1, anchor = NW) v_entry[ 2 ] = Entry(canvas2, bd = 0 , justify = CENTER, bg = '#7F7F7F' , width = 6 ) (v_entry[ 2 ]).insert( 0 , '202' ) (v_entry[ 2 ]).place(x = 100 , y = 125 ) txt1 = 'txt4txt4txt4txt4txt4txt4txt4' v_04 = canvas2.create_text( 30 , 150 , text = txt1, anchor = NW) v_entry[ 3 ] = Entry(canvas2, bd = 0 , justify = CENTER, bg = '#7F7F7F' , width = 6 ) (v_entry[ 3 ]).insert( 0 , '303' ) (v_entry[ 3 ]).place(x = 100 , y = 175 ) txt1 = 'txt5txt5txt5txt5txt5txt5txt5' v_05 = canvas2.create_text( 30 , 200 , text = txt1, anchor = NW) v_entry[ 4 ] = Entry(canvas2, bd = 0 , justify = CENTER, bg = '#7F7F7F' , width = 6 ) (v_entry[ 4 ]).insert( 0 , '404' ) (v_entry[ 4 ]).place(x = 100 , y = 225 ) txt1 = 'tx6txt6txt6txt6txt6txt6txt6' v_06 = canvas2.create_text( 30 , 250 , text = txt1, anchor = NW) v_entry[ 5 ] = Entry(canvas2, bd = 0 , justify = CENTER, bg = '#7F7F7F' , width = 6 ) (v_entry[ 5 ]).insert( 0 , '505' ) (v_entry[ 5 ]).place(x = 100 , y = 275 ) txt1 = 'tx7txt7tx7txt7txt7txt7txt7' v_07 = canvas2.create_text( 30 , 300 , text = txt1, anchor = NW) v_entry[ 6 ] = Entry(canvas2, bd = 0 , justify = CENTER, bg = '#7F7F7F' , width = 6 ) (v_entry[ 6 ]).insert( 0 , '606' ) (v_entry[ 6 ]).place(x = 100 , y = 325 ) txt1 = 'tx8txt8txt8txt8txt8txt8txt8' v_08 = canvas2.create_text( 30 , 350 , text = txt1, anchor = NW) list_v = [v_01, v_02, v_03, v_04, v_05, v_06, v_07, v_08] def fun_mooving(event): global v_entry, list_v y = int (event.delta / 2 ) for i1 in list_v: canvas2.move(i1, 0 , y) for i in v_entry: y1 = i.winfo_y() y1 + = y i.place(x = 100 , y = y1) canvas1 = Canvas(root, width = 600 , height = 800 , highlightthickness = 0 ) canvas1.place(x = 0 , y = 0 ) canvas2 = Canvas(canvas1, width = 600 , height = 750 , highlightthickness = 0 ) canvas2.place(x = 0 , y = 50 ) v_entry = [] for i in range ( 7 ): v_entry.append(Entry(canvas2, bd = 0 , justify = CENTER, width = 6 )) xxx() canvas2.bind_all( "<MouseWheel>" , fun_mooving) root.mainloop() |