Python Forum
The coordinates of the Entry widget (canvas) when moving
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The coordinates of the Entry widget (canvas) when moving
#1
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?

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


Messages In This Thread
The coordinates of the Entry widget (canvas) when moving - by berckut72 - Jan-04-2020, 08:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 701 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,536 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,008 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  [Tkinter] canvas widget scroll issue chrisdb 2 3,882 Apr-07-2021, 05:48 AM
Last Post: chrisdb
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,261 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  Entry Widget issue PA3040 16 6,865 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] password with Entry widget TAREKYANGUI 9 5,993 Sep-24-2020, 05:27 PM
Last Post: TAREKYANGUI
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,423 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to place global tk text widget in class or on canvas puje 1 2,340 Jul-04-2020, 09:25 AM
Last Post: deanhystad
  How to retreive the grid location of an Entry widget kenwatts275 7 4,638 Apr-24-2020, 11:39 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020